Image.st
author Claus Gittinger <cg@exept.de>
Thu, 24 Apr 1997 23:13:56 +0200
changeset 1668 95dafe4184d5
parent 1667 975687991916
child 1729 9cccc0fcea24
permissions -rw-r--r--
checkin from browser
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
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
     3
	      All Rights Reserved
0
48194c26a46c Initial revision
claus
parents:
diff changeset
     4
48194c26a46c Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
48194c26a46c Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
48194c26a46c Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
48194c26a46c Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
48194c26a46c Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
48194c26a46c Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
48194c26a46c Initial revision
claus
parents:
diff changeset
    11
"
48194c26a46c Initial revision
claus
parents:
diff changeset
    12
48194c26a46c Initial revision
claus
parents:
diff changeset
    13
Object subclass:#Image
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
    14
	instanceVariableNames:'bytes width height bitsPerPixel depth colorMap maxPixelValue
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
    15
		rowByteSize bitsPerSample samplesPerPixel photometric device
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
    16
		deviceForm monoDeviceForm fullColorDeviceForm mask
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
    17
		maskedPixelsAre0'
306
5070ca5adcb1 more for StaticColor visuals (OS/2 display)
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
    18
	classVariableNames:'Lobby DitherAlgorithm NumberOfDitherColors
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
    19
		CollectGarbageWhenRunningOutOfColors FileFormats
1385
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
    20
		ImageNotFoundQuerySignal BadImageFormatQuerySignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
    21
		ImageSaveErrorSignal FileCreationErrorSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
    22
		CannotRepresentImageSignal InformationLostQuerySignal'
306
5070ca5adcb1 more for StaticColor visuals (OS/2 display)
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
    23
	poolDictionaries:''
5070ca5adcb1 more for StaticColor visuals (OS/2 display)
Claus Gittinger <cg@exept.de>
parents: 305
diff changeset
    24
	category:'Graphics-Images'
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    25
!
48194c26a46c Initial revision
claus
parents:
diff changeset
    26
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
    27
!Image class methodsFor:'documentation'!
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    28
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    29
copyright
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    30
"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    31
 COPYRIGHT (c) 1991 by Claus Gittinger
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
    32
	      All Rights Reserved
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    33
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    34
 This software is furnished under a license and may be used
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    35
 only in accordance with the terms of that license and with the
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    36
 inclusion of the above copyright notice.   This software may not
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    37
 be provided or otherwise made available to, or used by, any
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    38
 other person.  No title to or ownership of the software is
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    39
 hereby transferred.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    40
"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    41
!
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    42
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    43
documentation
48194c26a46c Initial revision
claus
parents:
diff changeset
    44
"
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    45
    this class provides (some time in the future) representation
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    46
    for all kinds of images (monochrome, greyscale and color)
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    47
    and will finally replace Form. 
622
565e2301c064 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
    48
    For now (only ;-) depths of 1, 2, 4, 8, 16 and 24 are supported.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    49
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    50
    An Image keeps all of its information in a device independent way, 
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    51
    but may be associated to a device. 
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    52
    The data held keeps all information which was originally present, 
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    53
    even if the display-device has lower resolution.
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    54
    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
    55
    color information.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    56
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    57
    Images may be created manually (by providing a pixel array),
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    58
    by screen capture or by reading a file (using an ImageReader).
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    59
    This gives a device independent image.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    60
    For display, a device representation is required, which can be
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    61
    aquired by sending the 
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    62
        'onDevice:aDevice' 
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    63
    message to the image. This will create a (possibly dithered) device-form, 
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    64
    representing the image using the currently available colors.
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    65
286
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    66
    In rare cases, an explicit monochrome representation of the image is needed 
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    67
    (X servers take monochrome icons only), this can be created by sending
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    68
    it the message 
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    69
        'monochromeOn:aDevice'.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    70
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    71
    Also, it is planned to generate another hi-color resolution version,
286
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    72
    which uses its own colormap and allows the use of all 256 colors on an 8bit display 
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    73
    (this is not currently implemented).
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    74
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    75
    An images pixel interpretation is controlled by the photometric instance variable
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    76
    and (if that is #palette) a colorMap.
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    77
    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
    78
    (and using specialized colorMaps for b&w / greyScale images).
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    79
    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
    80
286
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    81
    To convert pictures from/to external file-formats, image readers are used
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    82
    which have the file-format knowledge built in. 
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    83
    There are readers for most common formats available 
286
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    84
    (see ImageReader and especially subclasses such as TIFFReader, GIFReader etc.).
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    85
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    86
    File formats are handled by subclasses of ImageReader, which understand
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    87
    a specific format. You can add more readers, by adding an association
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    88
    such as ('.jpg' -> JPEGReader) to the class variable 'FileFormats' 
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    89
    (see the classes #initialize method, which sets up some default, and the
286
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    90
    patches/display.rc files, which add more).
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    91
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    92
    Some algorithms used here (especially dithering & color allocation) are
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    93
    experimental and far from being perfect (some are very slow). 
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    94
    For now, the most common cases have been optimized and perform reasonably
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    95
    fast - however, with uncommon depth/visualType combinations, you may
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    96
    run into slower fallback methods ...
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    97
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    98
    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
    99
    (may) be done in the future if there is a demand for it ...
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   100
    Dithering can be controlled by the DitherAlgorithm classVariable:
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
   101
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   102
       DitherAlgorithm:
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   103
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   104
       nil                  a simple threshold algorithm
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   105
                            (i.e. for mono, p<0.5 -> black, p>=0.5 -> white)
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   106
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   107
       #pattern             patterned dither
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   108
                            (for p, take dithered color to fill pixel;
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   109
                             uses dithering in color-class)
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   110
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   111
       #error               error diffusion dither (Floyd-Steinberg)
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   112
                            planned - not yet implemented.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   113
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   114
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   115
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   116
    [instance variables:]
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   117
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   118
        width               <Integer>       the width in pixels
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   119
        height              <Integer>       the height in pixels
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   120
        bytes               <ByteArray>     the full image information
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   121
        photometric         <Symbol>        #rgb, #palette, #blackIs0 or #whiteIs0
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   122
        samplesPerPixel     <Integer>       the number of planes
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   123
        bitsPerSample       <Array>         the number of bits per plane
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   124
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   125
        colorMap            <Array>         only if photometric is #palette;
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   126
                                            maps pixel values to r/g/b values.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   127
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   128
        device              <Workstation>   the device on which deviceForm,
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   129
                                            monoDeviceForm and lowResDeviceForm are
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   130
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   131
        deviceForm          <Form>          the device form which gives the best
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   132
                                            possible aproximation of the image on
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   133
                                            device using standard colors.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   134
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   135
        monoDeviceForm      <Form>          the device form which gives a monochrome
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   136
                                            aproximation of the image on device.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   137
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   138
        fullColorDeviceForm <Form>          the device form which gives the best
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   139
                                            possible aproximation of the image on
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   140
                                            device using private colors.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   141
                                            (not yet implemented)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   142
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   143
        mask                <ImageMask>     an optional mask;
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   144
                                            if non-nil, only pixels for which the
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   145
                                            corresponding mask bit is non-zero
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   146
                                            are drawn.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   147
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   148
        maskedPixelsAre0    <Boolean>       a hint for image processors and drawers
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   149
                                            if true, masked pixels are known to be
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   150
                                            zero in the pixel bytes.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   151
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   152
        bitsPerPixel                        not used in ST/X
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   153
        depth                               - these have been added in instVar-slots
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   154
        maxPixelValue                       - according to the ST-80's image class.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   155
        rowByteSize                         - to allow loading of st-80 images
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   156
                                            - (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
   157
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   158
    [class variables:]
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   159
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   160
        Lobby               <Registry>      keeps track of known images
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   161
                                            (for resource freeing with garbage collector)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   162
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   163
        DitherAlgorithm     <Symbol>        defines how to dither
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   164
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   165
        NumberOfDitherColors <Integer>      defines, how many dither colors to use
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   166
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   167
        FileFormats         <Dictionary>    associates filename extensions to
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   168
                                            image reader classes (now set-up in startup-file)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   169
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   170
        CollectGarbageWhenRunningOutOfColors
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   171
                            <Boolean>       if true, and we run out of available
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   172
                                            device colors during creation of a
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   173
                                            device image, collect garbage for
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   174
                                            possible image reclamation.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   175
                                            If false, proceed immediately.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   176
                                            Default is true.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   177
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   178
        ImageNotFoundQuerySignal
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   179
                            <QuerySignal>   raised, if an image could not be loaded
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   180
                                            from a file. The parameter is the images
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   181
                                            fileName. 
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   182
                                            A handler may return a replacement
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   183
                                            image or proceed with nil.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   184
                                            If unhandled, a nil is returned from the
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   185
                                            image creation.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   186
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   187
        BadImageFormatQuerySignal
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   188
                            <QuerySignal>   raised, if an image could not be loaded
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   189
                                            from a file due to a file error or
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   190
                                            unsupported format. 
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   191
                                            A handler may return a replacement
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   192
                                            image or proceed with nil.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   193
                                            If unhandled, a nil is returned from the
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   194
                                            image creation.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   195
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   196
        ImageSaveErrorSignal
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   197
                            <Signal>        parent of errors below.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   198
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   199
        FileCreationErrorSignal
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   200
                            <Signal>        file could not be created when saving an
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   201
                                            image.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   202
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   203
        CannotRepresentImageSignal
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   204
                            <Signal>        the specified ImageReader cannot represent
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   205
                                            the given image.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   206
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   207
        InformationLostQuerySignal
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   208
                            <Signal>        the specified ImageReader can represent
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   209
                                            the given image, but some information
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   210
                                            (typically color resolution) is lost.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   211
                                            If unhandled, the save proceeds as usual.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   212
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
   213
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   214
    todo:
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   215
        support alpha masks
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   216
        cleanup the dithering & conversion code
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   217
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   218
    [See also:]
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   219
        Form Icon ImageReader
611
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   220
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   221
    [author:]
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   222
        Claus Gittinger
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   223
"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   224
649
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   225
!
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   226
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   227
examples
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   228
"
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   229
    reading from a file (many formats are supported):
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   230
                                                                        [exBegin]
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   231
        (Image fromFile:'bitmaps/gifImages/claus.gif') inspect
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   232
                                                                        [exEnd]
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   233
                                                                        [exBegin]
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   234
        (Image fromFile:'bitmaps/SmalltalkX.xbm') inspect
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   235
                                                                        [exEnd]
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   236
                                                                        [exBegin]
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   237
        (Image fromFile:'bitmaps/winBitmaps/okSmily_up.bmp') inspect
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   238
                                                                        [exEnd]
649
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   239
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   240
    inline image:
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   241
      default: depth=1 & #blackIs0
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   242
                                                                        [exBegin]
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   243
        (Image width:8 height:8
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   244
               fromArray:#( 2r11111111
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   245
                            2r10000001
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   246
                            2r10000001
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   247
                            2r10000001
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   248
                            2r10000001
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   249
                            2r10000001
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   250
                            2r10000001
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   251
                            2r11111111 )) inspect
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   252
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   253
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   254
      with #whiteIs0 photometric
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   255
                                                                        [exBegin]
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   256
        ((Image width:8 height:8
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   257
               fromArray:#( 2r11111111
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   258
                            2r10000001
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   259
                            2r10000001
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   260
                            2r10000001
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   261
                            2r10000001
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   262
                            2r10000001
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   263
                            2r10000001
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   264
                            2r11111111 ))
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   265
            photometric:#whiteIs0)
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   266
                 inspect
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   267
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   268
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   269
      with a colorMap
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   270
                                                                        [exBegin]
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   271
        ((Image width:8 height:8
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   272
               fromArray:#( 2r11111111
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   273
                            2r10000001
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   274
                            2r10000001
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   275
                            2r10000001
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   276
                            2r10000001
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   277
                            2r10000001
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   278
                            2r10000001
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   279
                            2r11111111 ))
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   280
            colorMap:(Array with:(Color red)
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   281
                            with:(Color yellow)))
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   282
                 inspect
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   283
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   284
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   285
      a depth4 greyScale image:
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   286
                                                                        [exBegin]
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   287
        (Depth4Image
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   288
             width:8 
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   289
             height:4
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   290
             fromArray:#[ 
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   291
                            16r00 16r11 16r22 16r33
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   292
                            16r44 16r55 16r66 16r77
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   293
                            16r88 16r99 16raa 16rbb
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   294
                            16rcc 16rdd 16ree 16rff 
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   295
                        ]) inspect
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   296
                                                                        [exEnd]
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   297
        ((Depth4Image
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   298
             width:4 
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   299
             height:4
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   300
             fromArray:#[ 
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   301
                            16r01 16r23
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   302
                            16r45 16r67
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   303
                            16r89 16rab
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   304
                            16rcd 16ref 
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   305
                        ])
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   306
            magnifiedBy:30)
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   307
                 inspect
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   308
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   309
      the following has the same effect:
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   310
                                                                        [exBegin]
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   311
        ((Image
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   312
             width:4 
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   313
             height:4
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   314
             depth:4
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   315
             fromArray:#[ 
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   316
                            16r01 16r23
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   317
                            16r45 16r67
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   318
                            16r89 16rab
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   319
                            16rcd 16ref 
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   320
                        ])
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   321
            magnifiedBy:30)
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   322
                 inspect
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   323
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   324
      with reverse grey-interpretation:
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   325
                                                                        [exBegin]
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   326
        ((Depth4Image
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   327
             width:4 
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   328
             height:4
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   329
             fromArray:#[ 
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   330
                            16r01 16r23
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   331
                            16r45 16r67
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   332
                            16r89 16rab
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   333
                            16rcd 16ref 
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   334
                        ])
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   335
            photometric:#whiteIs0;
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   336
            magnifiedBy:30)
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   337
                 inspect
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   338
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   339
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   340
      with 1-bit-per-pixel rgb interpretation:
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   341
                                                                        [exBegin]
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   342
        ((Depth4Image
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   343
             width:4 
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   344
             height:4
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   345
             fromArray:#[ 
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   346
                            16r01 16r23
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   347
                            16r45 16r67
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   348
                            16r89 16rab
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   349
                            16rcd 16ref 
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   350
                        ])
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   351
            photometric:#rgb;
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   352
            samplesPerPixel:3;
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   353
            bitsPerSample:#(1 1 1);
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   354
            magnifiedBy:30)
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   355
                 inspect
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   356
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   357
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   358
      with 1/2/1 rgb interpretation:
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   359
                                                                        [exBegin]
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   360
        ((Depth4Image
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   361
             width:4 
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   362
             height:4
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   363
             fromArray:#[ 
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   364
                            16r01 16r23
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   365
                            16r45 16r67
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   366
                            16r89 16rab
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   367
                            16rcd 16ref 
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   368
                        ])
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   369
            photometric:#rgb;
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   370
            samplesPerPixel:3;
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   371
            bitsPerSample:#(1 2 1);
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   372
            magnifiedBy:30)
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   373
                 inspect
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   374
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   375
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   376
      a 2/2/0 rgb image (i.e. no blue):
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   377
                                                                        [exBegin]
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   378
         |i|
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   379
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   380
         i := Depth4Image
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   381
                    width:4
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   382
                    height:4
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   383
                    fromArray:#[ 16r01 16r23
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   384
                                 16r45 16r67
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   385
                                 16r89 16rab
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   386
                                 16rcd 16ref ].
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   387
         i photometric:#rgb.
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   388
         i samplesPerPixel:3.
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   389
         i bitsPerSample:#(2 2 0).
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   390
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   391
         i := i magnifiedBy:30.
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   392
         i inspect.
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   393
                                                                        [exEnd]
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   394
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   395
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   396
      a 0/0/4 rgb image (i.e. no red or green):
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   397
                                                                        [exBegin]
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   398
         |i|
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   399
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   400
         i := Depth4Image
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   401
                    width:4
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   402
                    height:4
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   403
                    fromArray:#[ 16r01 16r23
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   404
                                 16r45 16r67
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   405
                                 16r89 16rab
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   406
                                 16rcd 16ref ].
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   407
         i photometric:#rgb.
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   408
         i samplesPerPixel:3.
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   409
         i bitsPerSample:#(0 0 4).
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   410
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   411
         i := i magnifiedBy:30.
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   412
         i inspect.
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   413
                                                                        [exEnd]
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   414
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   415
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   416
      a 2plane greyscale image:
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   417
                                                                        [exBegin]
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   418
        ((Depth2Image
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   419
             width:4 
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   420
             height:4
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   421
             fromArray:#[ 
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   422
                            4r0123
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   423
                            4r1230
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   424
                            4r2301
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   425
                            4r3012 
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   426
                        ])
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   427
            magnifiedBy:30)
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   428
                 inspect
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   429
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   430
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   431
      with colors:
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   432
                                                                        [exBegin]
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   433
        ((Depth2Image
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   434
             width:4 
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   435
             height:4
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   436
             fromArray:#[ 
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   437
                            4r0123
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   438
                            4r1230
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   439
                            4r2301
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   440
                            4r3012 
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   441
                        ])
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   442
            colorMap:(Array with:(Color black)
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   443
                            with:(Color red)
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   444
                            with:(Color green)
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   445
                            with:(Color blue));
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   446
            magnifiedBy:30)
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   447
                 inspect
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   448
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   449
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   450
      depth8 image with 3/3/2 rgb interpretation:
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   451
                                                                        [exBegin]
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   452
        ((Depth8Image
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   453
             width:16 
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   454
             height:16
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   455
             fromArray:(ByteArray withAll:(0 to:16rFF)))
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   456
            photometric:#rgb;
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   457
            samplesPerPixel:3;
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   458
            bitsPerSample:#(3 3 2);
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   459
            magnifiedBy:30)
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   460
                 inspect
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   461
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   462
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   463
      depth8 image with 2/2/2 rgb interpretation:
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   464
                                                                        [exBegin]
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   465
        ((Depth8Image
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   466
             width:8 
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   467
             height:8
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   468
             fromArray:(ByteArray withAll:(0 to:16r3F)))
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   469
            photometric:#rgb;
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   470
            samplesPerPixel:3;
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   471
            bitsPerSample:#(2 2 2);
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   472
            magnifiedBy:30)
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   473
                 inspect
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   474
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   475
649
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   476
    storing (only a few formats are currently supported):
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   477
                                                                        [exBegin]
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   478
        |img|
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   479
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   480
        img := Image fromFile:'bitmaps/okSmily_up.bmp'.
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   481
        img saveOn:'myImage.tiff'.
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   482
        (Image fromFile:'myImage.tiff') inspect
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   483
                                                                        [exEnd]
649
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   484
    magnifying (any factor):
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   485
                                                                        [exBegin]
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   486
        ((Image fromFile:'bitmaps/claus.gif') 
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   487
            magnifiedTo:(48@48))
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   488
                inspect
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   489
                                                                        [exEnd]
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   490
                                                                        [exBegin]
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   491
        ((Image fromFile:'bitmaps/claus.gif') 
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   492
            magnifiedBy:0.7)
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   493
                inspect
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   494
                                                                        [exEnd]
649
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   495
    rotating (currently, only multiples of 90 degrees are supported):
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   496
                                                                        [exBegin]
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   497
        ((Image fromFile:'bitmaps/claus.gif') 
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   498
            rotated:90)
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   499
                inspect
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   500
                                                                        [exEnd]
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   501
                                                                        [exBegin]
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   502
        (((Image fromFile:'bitmaps/claus.gif') 
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   503
            magnifiedBy:0.3@0.7) rotated:270)
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   504
                inspect
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   505
                                                                        [exEnd]
649
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   506
"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   507
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
   508
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   509
!Image class methodsFor:'initialization'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   510
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   511
addReader:aReaderClass suffix:aSuffix
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   512
    "register an additional image reader.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   513
     This is provided for subclasses, to regster themself when
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   514
     loaded (or from the startup scripts)"
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   515
1309
2a1d271ef7f8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1307
diff changeset
   516
    FileFormats isNil ifTrue:[
2a1d271ef7f8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1307
diff changeset
   517
	self initializeFileFormatTable
2a1d271ef7f8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1307
diff changeset
   518
    ].
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   519
    FileFormats at:(aSuffix asLowercase) put:aReaderClass.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   520
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   521
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   522
     Image addReader:GIFReader suffix:'gif'
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   523
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   524
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   525
    "Modified: 1.2.1997 / 14:42:54 / cg"
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   526
!
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   527
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   528
fileFormats
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   529
    "return the collection of supported file formats.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   530
     The returned dictionary maps file-extensions to image reader classes."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   531
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   532
    FileFormats isNil ifTrue:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   533
	self initializeFileFormatTable
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   534
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   535
    ^ FileFormats
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   536
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   537
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   538
     Image fileFormats
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   539
    "
100
1b0b86c77397 co !!:*
claus
parents: 89
diff changeset
   540
!
1b0b86c77397 co !!:*
claus
parents: 89
diff changeset
   541
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   542
flushDeviceImages
869
464ffa8c0c67 comment
Claus Gittinger <cg@exept.de>
parents: 861
diff changeset
   543
    "simply release all deviceForms"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   544
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   545
    Lobby do:[:anImage |
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   546
	anImage restored
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   547
    ]
869
464ffa8c0c67 comment
Claus Gittinger <cg@exept.de>
parents: 861
diff changeset
   548
464ffa8c0c67 comment
Claus Gittinger <cg@exept.de>
parents: 861
diff changeset
   549
    "Modified: 15.6.1996 / 15:45:02 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   550
!
48194c26a46c Initial revision
claus
parents:
diff changeset
   551
48194c26a46c Initial revision
claus
parents:
diff changeset
   552
initialize
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
   553
    "initialize class constants"
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
   554
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   555
    "setup tracker of known pictures"
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   556
    Lobby isNil ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   557
	Lobby := Registry new.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   558
	ObjectMemory addDependent:self.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   559
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   560
	"/ define the algorithm to use for dithering - 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   561
	"/ supported values are:
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   562
	"/      #threshold
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   563
	"/      #ordered
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   564
	"/      #floydSteinberg
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   565
	"/      #burkes
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   566
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   567
	DitherAlgorithm := #floydSteinberg.   
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   568
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   569
	(Display notNil and:[Display hasGrayscales]) ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   570
	    NumberOfDitherColors := 64
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   571
	] ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   572
	    "as far as I remember, this is about the number of grey values, the eye can distinguish"
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   573
	    NumberOfDitherColors := 100
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   574
	].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   575
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   576
	"define reader classes"
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   577
	FileFormats isNil ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   578
	    self initializeFileFormatTable
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   579
	].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   580
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   581
	CollectGarbageWhenRunningOutOfColors := false.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   582
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   583
	ImageNotFoundQuerySignal := QuerySignal new.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   584
	ImageNotFoundQuerySignal nameClass:self message:#imageNotFoundQuerySignal.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   585
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   586
	ImageSaveErrorSignal := ErrorSignal newSignalMayProceed:true.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   587
	ImageSaveErrorSignal nameClass:self message:#imageSaveErrorSignal.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   588
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   589
	FileCreationErrorSignal := ImageSaveErrorSignal newSignalMayProceed:true.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   590
	FileCreationErrorSignal nameClass:self message:#fileCreationErrorSignal.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   591
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   592
	CannotRepresentImageSignal := ImageSaveErrorSignal newSignalMayProceed:true.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   593
	CannotRepresentImageSignal nameClass:self message:#cannotRepresentImageSignal.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   594
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   595
	InformationLostQuerySignal := QuerySignal new.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   596
	InformationLostQuerySignal nameClass:self message:#informationLostQuerySignal.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   597
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   598
	BadImageFormatQuerySignal := QuerySignal new.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   599
	BadImageFormatQuerySignal nameClass:self message:#badImageFormatQuerySignal.
386
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
   600
    ]
748
818c6312acd1 grey vs. gray
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   601
1385
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
   602
    "Modified: 27.2.1997 / 12:42:13 / cg"
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   603
!
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   604
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   605
initializeFileFormatTable
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   606
    "initialize a default table to map from file extension to reader class.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   607
     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
   608
     see the 'smalltalk.rc'/'display.rc' startup files for a real (full) map."
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   609
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   610
    FileFormats := Dictionary new.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   611
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   612
    FileFormats at:'xbm'  put:XBMReader.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   613
    FileFormats at:'tiff' put:TIFFReader.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   614
    FileFormats at:'gif'  put:GIFReader.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   615
"/    FileFormats at:'img'  put:IMGReader.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   616
"/    FileFormats at:'icon' put:SunRasterReader.
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   617
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   618
    "
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   619
     Image initializeFileFormatTable
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   620
    "
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   621
1593
a88f08caacef commentary
Claus Gittinger <cg@exept.de>
parents: 1591
diff changeset
   622
    "Modified: 14.4.1997 / 17:16:02 / cg"
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   623
!
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   624
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
   625
update:something with:aParameter from:changedObject
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   626
    "flush all device specific stuff when restarted from a snapshot"
48194c26a46c Initial revision
claus
parents:
diff changeset
   627
48194c26a46c Initial revision
claus
parents:
diff changeset
   628
    (something == #restarted) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   629
	self flushDeviceImages
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   630
    ]
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
   631
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
   632
    "Created: 21.6.1996 / 19:47:43 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   633
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
   634
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   635
!Image class methodsFor:'instance creation'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   636
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   637
extent:ext depth:d bits:bits
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   638
    "ST-80 compatibility; assume 32-bit padding"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   639
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   640
    ^ self extent:ext depth:d bits:bits pad:32
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   641
!
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   642
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   643
extent:ext depth:d bits:bits pad:padding
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   644
    "ST-80 compatibility"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   645
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   646
    ^ self width:ext x height:ext y depth:d fromArray:bits pad:padding
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   647
!
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   648
1276
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   649
extent:ext depth:d bitsPerPixel:bpp palette:aColormap usingBits:bits
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   650
    "ST-80 compatibility"
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   651
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   652
    |img|
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   653
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   654
    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
   655
    img colorMap:aColormap.
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   656
    ^ img
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   657
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   658
    "Created: 25.1.1997 / 03:50:22 / cg"
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   659
    "Modified: 25.1.1997 / 12:27:35 / cg"
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   660
!
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   661
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   662
extent:ext depth:d palette:aColormap
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   663
    "create & return a blank image of the given size.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   664
     ST-80 compatibility"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   665
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   666
    |newImage emptyBits|
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   667
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   668
    newImage := (self implementorForDepth:d) new.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   669
    newImage width:ext x height:ext y depth:d palette:aColormap.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   670
    emptyBits := ByteArray new:(newImage bytesPerRow * ext y).
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   671
    newImage bits:emptyBits.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   672
    ^ newImage
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   673
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   674
    "
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   675
     Image extent:16@16 depth:8 palette:nil
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   676
     Image extent:16@16 depth:4 palette:nil
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   677
     Image extent:16@16 depth:2 palette:nil
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   678
    "
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   679
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   680
    "Created: 6.3.1997 / 15:24:01 / cg"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   681
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   682
1070
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   683
extent:ext depth:d palette:aColormap bits:bits
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   684
    "ST-80 compatibility"
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   685
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   686
    ^ self extent:ext depth:d palette:aColormap bits:bits pad:16
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   687
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   688
    "Modified: 7.10.1996 / 11:32:16 / cg"
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   689
!
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   690
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   691
extent:ext depth:d palette:aColormap bits:bits pad:padding
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   692
    "ST-80 compatibility"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   693
1070
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   694
    |img|
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   695
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   696
    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
   697
    img colorMap:aColormap.
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   698
    ^ img
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   699
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   700
    "Modified: 7.10.1996 / 11:32:00 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   701
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   702
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   703
extent:ext fromArray:bits offset:offset
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   704
    "ST-80 compatibility"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   705
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   706
    ^ self width:ext x height:ext y fromArray:bits
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   707
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   708
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   709
fromForm:aForm
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   710
    "create & return an Image given a aForm"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   711
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   712
    |depth device vis img|
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   713
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   714
    depth := aForm depth.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   715
    device := aForm device.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   716
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   717
    (device notNil and:[depth == device depth]) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   718
	"/
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   719
	"/ for truecolor displays, return a Depth24Image
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   720
	"/ (must do this for depth15 & depth16 displays, since
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   721
	"/  Depth16Image has no way to specify r/g/b masks ...)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   722
	"/
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   723
	vis := device visualType.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   724
	(vis == #TrueColor or:[vis == #DirectColor]) ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   725
	    depth > 8 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   726
		depth := 24.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   727
	    ]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   728
	].
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   729
    ].
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   730
    img := (self implementorForDepth:depth) new.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   731
    device isNil ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   732
	^ img fromForm:aForm.
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   733
    ].
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   734
    ^ img from:aForm in:(0@0 extent:(aForm extent))
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   735
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   736
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   737
     |f|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   738
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   739
     f := Form width:16 height:16.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   740
     f clear.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   741
     f displayLineFromX:0 y:0 toX:15 y:15.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   742
     f inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   743
     (Image fromForm:f) inspect
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   744
    "
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   745
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   746
    "
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   747
     |f|
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   748
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   749
     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
   750
     f clear.
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   751
     f paint:(Color red).
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   752
     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
   753
     f paint:(Color green).
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   754
     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
   755
     f inspect.
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   756
     (Image fromForm:f) inspect
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   757
    "
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   758
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   759
    "Modified: 11.7.1996 / 11:21:42 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   760
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   761
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   762
fromImage:anImage
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   763
    "create & return an Image given another image. This can be used to
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   764
     convert an image to another depth."
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   765
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   766
    (self == Image or:[anImage class == self]) ifTrue:[^ anImage].
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   767
    ^ self new fromImage:anImage.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   768
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   769
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   770
     |i1 i8|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   771
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   772
     i1 := Image fromFile:'bitmaps/SBrowser.xbm'.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   773
     i8 := Depth8Image fromImage:i1.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   774
     i8 inspect
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   775
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   776
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   777
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   778
fromSubImage:anImage in:aRectangle
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   779
    "create & return an Image from a rectangular area in another image. 
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   780
     This can also be used to get a subimage in another depth."
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   781
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   782
    |newImage|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   783
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   784
    self == Image ifTrue:[
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   785
        newImage := (self implementorForDepth:anImage depth) new.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   786
    ] ifFalse:[
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   787
        newImage := self new.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   788
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   789
    ^ newImage fromSubImage:anImage in:aRectangle.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   790
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   791
    "
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   792
     |i1 i8|
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   793
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   794
     i1 := Image fromFile:'bitmaps/garfield.gif'.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   795
     i8 := Depth8Image fromSubImage:i1 in:(0@0 corner:20@20).
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   796
     i8 inspect
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   797
    "
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   798
    "
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   799
     |i1 i8|
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   800
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   801
     i1 := Image fromFile:'bitmaps/claus.gif'.
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   802
     i8 := Depth8Image fromSubImage:i1 in:(70@50 extent:50@50).
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   803
     i8 inspect
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   804
    "
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   805
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   806
     |i1 i8|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   807
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   808
     i1 := Image fromFile:'bitmaps/claus.gif'.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   809
     i8 := Image fromSubImage:i1 in:(70@50 extent:50@50).
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   810
     i8 inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   811
    "
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   812
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   813
    "Created: 20.9.1995 / 01:05:43 / claus"
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   814
    "Modified: 24.4.1997 / 23:13:02 / cg"
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   815
!
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   816
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   817
new
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   818
    "create a new image. Redefined to set the photometric to
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   819
     greyScale with black being 0 as default."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   820
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   821
    ^ super new photometric:(self defaultPhotometric)
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   822
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   823
    "Modified: 10.6.1996 / 18:08:37 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   824
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   825
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   826
width:w height:h
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   827
    "create a new image, given width, height. Assume a depth of 1."
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   828
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   829
    |cls|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   830
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   831
    cls := self.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   832
    cls == Image ifTrue:[
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   833
	cls := self implementorForDepth:1
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   834
    ].
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   835
    ^ cls new width:w height:h depth:1 
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   836
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   837
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   838
width:w height:h depth:d
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   839
    "create a new image, given width, height and depth"
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   840
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   841
    ^ (self implementorForDepth:d) new
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   842
	width:w height:h depth:d
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   843
!
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   844
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   845
width:w height:h depth:d fromArray:pixelData
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   846
    "create a new image, given width, height, depth and data.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   847
     Data must be a ByteArray containing correctly aligned bits for the specified
134
claus
parents: 132
diff changeset
   848
     depth (8-bit padded)."
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   849
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   850
    ^ (self implementorForDepth:d) new 
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   851
		width:w height:h depth:d fromArray:pixelData
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   852
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   853
    "
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   854
     Image width:8 
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   855
	   height:8
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   856
	   depth:1
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   857
	   fromArray:#[2r11001100
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   858
		       2r00110011
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   859
		       2r11001100
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   860
		       2r00110011
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   861
		       2r11001100
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   862
		       2r00110011
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   863
		       2r11001100
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   864
		       2r00110011].
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   865
    "
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   866
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   867
    "
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   868
     Image width:8 
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   869
	   height:8
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   870
	   depth:2 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   871
	   fromArray:#[4r1100 4r1100
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   872
		       4r0011 4r0011
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   873
		       4r1100 4r1100
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   874
		       4r0011 4r0011
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   875
		       4r1100 4r1100
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   876
		       4r0011 4r0011
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   877
		       4r1100 4r1100
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   878
		       4r0011 4r0011].
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   879
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   880
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   881
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   882
     Image width:8 
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   883
	   height:8
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   884
	   depth:4 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   885
	   fromArray:#[16r00 16r01 16rf0 16rf1
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   886
		       16r02 16r03 16rf2 16rf3
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   887
		       16r04 16r05 16rf4 16rf5
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   888
		       16r06 16r07 16rf6 16rf7
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   889
		       16r08 16r09 16rf8 16rf9
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   890
		       16r0a 16r0b 16rfa 16rfb
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   891
		       16r0c 16r0d 16rfc 16rfd
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   892
		       16r0e 16r0f 16rfe 16rff].
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   893
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   894
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   895
    "Modified: 10.6.1996 / 18:18:10 / cg"
132
claus
parents: 125
diff changeset
   896
!
claus
parents: 125
diff changeset
   897
134
claus
parents: 132
diff changeset
   898
width:w height:h depth:d fromArray:pixelData pad:padding
claus
parents: 132
diff changeset
   899
    "create a new image, given width, height, depth and data.
claus
parents: 132
diff changeset
   900
     Data must be a ByteArray containing correctly aligned bits for the specified
claus
parents: 132
diff changeset
   901
     depth."
claus
parents: 132
diff changeset
   902
claus
parents: 132
diff changeset
   903
    |img newBits srcRowBytes dstRowBytes srcIndex dstIndex|
claus
parents: 132
diff changeset
   904
claus
parents: 132
diff changeset
   905
    img := (self implementorForDepth:d) new width:w height:h depth:d .
claus
parents: 132
diff changeset
   906
claus
parents: 132
diff changeset
   907
    padding ~~ 8 ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   908
	"must repad; ST/X uses byte padding, while ST-80 uses longword
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   909
	 padding. This is stupid, and may be changed in ST/X with future versions.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   910
	"
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   911
	dstRowBytes := img bytesPerRow.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   912
	srcRowBytes := ((w * d + padding - 1) bitShift:-5) bitShift:2.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   913
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   914
	newBits := ByteArray new:(dstRowBytes * h).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   915
	srcIndex := 1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   916
	dstIndex := 1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   917
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   918
	1 to:h do:[:row |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   919
	    newBits replaceFrom:dstIndex 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   920
			     to:(dstIndex + dstRowBytes - 1)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   921
			   with:pixelData
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   922
		     startingAt:srcIndex.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   923
	    srcIndex := srcIndex + srcRowBytes.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   924
	    dstIndex := dstIndex + dstRowBytes.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   925
	].
134
claus
parents: 132
diff changeset
   926
    ] ifFalse:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   927
	pixelData class isBytes ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   928
	    newBits := ByteArray withAll:pixelData
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   929
	] ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   930
	    newBits := pixelData
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   931
	]
134
claus
parents: 132
diff changeset
   932
    ].
claus
parents: 132
diff changeset
   933
    img bits:newBits.
claus
parents: 132
diff changeset
   934
    ^ img
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   935
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   936
    "Modified: 8.6.1996 / 10:07:47 / cg"
134
claus
parents: 132
diff changeset
   937
!
claus
parents: 132
diff changeset
   938
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   939
width:w height:h fromArray:anArray
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   940
    "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
   941
     receiving class is Image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   942
     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
   943
     (i.e. 8 bits per byte)."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   944
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   945
    |cls d pixels|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   946
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   947
    cls := self.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   948
    cls == Image ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   949
	cls := self implementorForDepth:1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   950
	d := 1.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   951
    ] ifFalse:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   952
	d := cls imageDepth
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   953
    ].
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   954
    anArray class isBytes ifFalse:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   955
	pixels := ByteArray withAll:anArray
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   956
    ] ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   957
	pixels := anArray
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   958
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   959
    ^ cls new width:w height:h depth:d fromArray:pixels
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   960
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   961
    "
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   962
     Image width:8 
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   963
	   height:8 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   964
	   fromArray:#[2r11001100
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   965
		       2r00110011
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   966
		       2r11001100
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   967
		       2r00110011
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   968
		       2r11001100
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   969
		       2r00110011
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   970
		       2r11001100
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
   971
		       2r00110011].
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   972
    "
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   973
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   974
    "Modified: 8.6.1996 / 10:07:26 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   975
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   976
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
   977
!Image class methodsFor:'Signal constants'!
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
   978
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   979
badImageFormatQuerySignal
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   980
    "return the (query-) signal, which is raised if some
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   981
     bitmap-image could not be loaded due to an unrecognized format.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   982
     If unhandled, the image-load returns nil.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   983
     Otherwise, it returns whatever the handler proceeds with.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   984
     The exception gets either the images fileName or an input stream
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   985
     as parameter"
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   986
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   987
    ^ BadImageFormatQuerySignal
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   988
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   989
    "Created: 1.2.1997 / 14:40:29 / cg"
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   990
!
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   991
1385
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
   992
cannotRepresentImageSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
   993
    "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
   994
     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
   995
     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
   996
     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
   997
     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
   998
     (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
   999
     format then."
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1000
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1001
    ^ CannotRepresentImageSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1002
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1003
    "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
  1004
!
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1005
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1006
fileCreationErrorSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1007
    "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
  1008
     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
  1009
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1010
    ^ FileCreationErrorSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1011
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1012
    "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
  1013
!
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1014
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1015
imageNotFoundQuerySignal
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1016
    "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
  1017
     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
  1018
     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
  1019
     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
  1020
     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
  1021
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1022
    ^ ImageNotFoundQuerySignal
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1023
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1024
    "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
  1025
!
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1026
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1027
imageSaveErrorSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1028
    "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
  1029
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1030
    ^ ImageSaveErrorSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1031
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1032
    "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
  1033
!
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1034
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1035
informationLostQuerySignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1036
    "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
  1037
     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
  1038
     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
  1039
     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
  1040
     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
  1041
     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
  1042
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1043
    ^ InformationLostQuerySignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1044
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1045
    "Created: 27.2.1997 / 12:43:50 / cg"
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1046
! !
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1047
1230
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1048
!Image class methodsFor:'cleanup'!
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1049
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1050
releaseResourcesOnDevice:aDevice
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1051
    "this is sent when a display connection is closed,
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1052
     to release all cached Images from that device"
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1053
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1054
    Lobby 
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1055
	unregisterAllForWhich:[:anImage | 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1056
		|ok|
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1057
		ok := anImage graphicsDevice == aDevice.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1058
		ok ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1059
		    anImage quickRelease
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1060
		].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1061
		ok
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1062
	]
1230
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1063
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1064
    "Created: 16.1.1997 / 19:30:44 / cg"
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1065
    "Modified: 16.1.1997 / 19:33:49 / cg"
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1066
! !
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1067
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  1068
!Image class methodsFor:'file reading'!
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1069
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1070
fromFile:aFileName
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1071
    "read an image from a file - this methods tries to find
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1072
     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
  1073
     and lets the appropriate reader read the file.
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1074
     Also, all bitmap directories along the searchPath are checked
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1075
     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
  1076
     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
  1077
     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
  1078
     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
  1079
     proceed with some replacement image. If unhandled, nil is returned."
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1080
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1081
    |image name fn nm inStream suffix readerClass|
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1082
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1083
    "
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1084
     before trying each reader, check if the file is readable
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1085
    "
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1086
    name := aFileName asFilename name.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1087
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1088
    inStream := Smalltalk systemFileStreamFor:name.
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1089
    inStream isNil ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1090
	inStream := Smalltalk bitmapFileStreamFor:name.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1091
	inStream isNil ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1092
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1093
	    "/ this signal is a query - if noone seems to
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1094
	    "/ care, return nil.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1095
	    "/ However, a handler may provide a replacement.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1096
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1097
"/            ('IMAGE: ' , aFileName , ' does not exist or is not readable') infoPrintCR.
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1098
	    ^ ImageNotFoundQuerySignal
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1099
			raiseRequestWith:aFileName
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1100
			errorString:('IMAGE: ''' , aFileName , ''' does not exist or is not readable').
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1101
	].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1102
	name := 'bitmaps/' , name.
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1103
    ].
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1104
    inStream close.
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1105
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1106
    nm := name.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1107
    fn := nm asFilename.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1108
    suffix := fn suffix.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1109
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1110
    "/
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1111
    "/ handle compressed-suffix
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1112
    "/
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1113
    (#('Z' 'gz') includes:suffix) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1114
	fn := fn withoutSuffix.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1115
	nm := fn name.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1116
	suffix := fn suffix.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1117
    ].
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1118
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1119
    suffix isEmpty ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1120
	suffix := nm.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1121
    ].
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1122
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1123
    "/
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1124
    "/ get the imageReader class from the files extension
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1125
    "/ and ask it first
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1126
1469
12e083fba6e0 handle no-suffix case in #fromFile:
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
  1127
    readerClass := FileFormats at:(suffix asLowercase) ifAbsent:nil.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1128
    readerClass notNil ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1129
	image := readerClass fromFile:name.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1130
	image notNil ifTrue:[^ image].
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1131
    ].
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1132
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1133
    "
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1134
     no known extension - ask all readers if they know
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1135
     this format ...
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1136
     ... these look into the file, and investigate the header.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1137
     therefore, it takes a bit longer.
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1138
    "
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1139
    FileFormats do:[:readerClass |
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1140
	readerClass notNil ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1141
	    (readerClass isValidImageFile:name) ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1142
		^ readerClass fromFile:name 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1143
	    ]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1144
	]
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1145
    ].
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1146
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1147
    "/ nope - unknown format
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1148
    "/
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1149
    "/ this signal is a query - if noone seems to
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1150
    "/ care, return nil.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1151
    "/ However, a handler may provide a replacement.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1152
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1153
"/    'IMAGE: unknown image file format: ' infoPrint. aFileName infoPrintNL.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1154
    ^ ImageNotFoundQuerySignal
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1155
		raiseRequestWith:aFileName
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1156
		errorString:('IMAGE: unknown image file format: ''' , aFileName , '''').
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1157
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1158
    "
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1159
     Image fromFile:'bitmaps/dano.tiff'
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1160
     Image fromFile:'bitmaps/test.fax'
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1161
     Image fromFile:'bitmaps/voice.tiff'
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1162
     Image fromFile:'voice.tiff'
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1163
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1164
     Image fromFile:'../fileIn/bitmaps/claus.gif'
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1165
     Image fromFile:'../fileIn/bitmaps/garfield.gif'
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1166
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1167
     Image fromFile:'../fileIn/bitmaps/founders.im8'
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1168
     Image fromFile:'../goodies/faces/next.com/steve.face'
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1169
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1170
     Image fromFile:'/LocalLibrary/Images/OS2/dos3.ico'
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1171
     Image fromFile:'bitmaps/globe1.xbm'
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1172
     Image fromFile:'bitmaps/globe1.xbm.Z'
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1173
     Image fromFile:'bitmaps/hello_world.icon'
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1174
    "
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1175
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1176
    "
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1177
     Image fromFile:'fooBar'
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1178
    "
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1179
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1180
    "giving a messgage for non-existing images:
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1181
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1182
     Image imageNotFoundQuerySignal 
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1183
     handle:[:ex |
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1184
	ex errorString printCR.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1185
	ex proceedWith:nil
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1186
     ] do:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1187
	 Image fromFile:'fooBar'
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1188
     ]
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1189
    "
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1190
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1191
    "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
  1192
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1193
     Image imageNotFoundQuerySignal 
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1194
     answer:(Image fromFile:'bitmaps/SmalltalkX.xbm')
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1195
     do:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1196
	 Image fromFile:'fooBar'
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1197
     ]
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1198
    "
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1199
1469
12e083fba6e0 handle no-suffix case in #fromFile:
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
  1200
    "Modified: 19.3.1997 / 23:14:44 / cg"
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1201
!
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1202
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1203
fromFile:aFileName on:aDevice
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1204
    "read an image from a file and prepare a device representation.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1205
     Return nil (or whatever a handler returned), 
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1206
     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
  1207
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1208
    |img|
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1209
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1210
    img := self fromFile:aFileName.
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1211
    img notNil ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1212
	^ img on:aDevice
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1213
    ].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1214
    ^ nil
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1215
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1216
    "Modified: 1.2.1997 / 14:48:07 / cg"
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1217
!
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1218
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1219
fromFile:aFileName resolution:res
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1220
    "read an image from a file and (if required) scale the image
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1221
     as appropriate (only with very high resolution displays).
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1222
     Return nil (or whatever a handler returned), 
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1223
     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
  1224
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1225
    ^ self fromFile:aFileName resolution:res on:nil
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1226
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1227
    "Created: 19.12.1996 / 14:02:13 / cg"
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1228
    "Modified: 1.2.1997 / 14:48:16 / cg"
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1229
!
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1230
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1231
fromFile:aFileName resolution:dpi on:aDevice
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1232
    "read an image from a file and (if required) scale the image
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1233
     as appropriate (only with very high resolution displays).
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1234
     Prepare a device representation.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1235
     Return nil (or whatever a handler returned), 
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1236
     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
  1237
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1238
    |img dev dpiH mag|
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1239
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1240
    img := self fromFile:aFileName.
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1241
    img isNil ifTrue:[^ nil].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1242
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1243
    "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
  1244
    dev := aDevice.
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1245
    dev isNil ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1246
	"should not happen ..."
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1247
	dev := Screen current
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1248
    ].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1249
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1250
    dpiH := dev horizontalPixelPerInch.
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1251
    ((dpi >= (dpiH * 0.75)) and:[dpi <= (dpiH * 1.5)]) ifTrue:[^ img].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1252
    mag := (dpiH / dpi) rounded.
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1253
    mag = 0 ifTrue:[^ img].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1254
    mag = 1 ifTrue:[^ img].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1255
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1256
    img := img magnifiedBy:(mag @ mag).
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1257
    aDevice notNil ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1258
	"should not happen ..."
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1259
	^ img on:aDevice
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1260
    ].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1261
    ^ img
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1262
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1263
    "Modified: 1.2.1997 / 14:48:20 / cg"
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1264
!
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1265
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1266
fromStream:aStream
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1267
    "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
  1268
     out the file format itself (by contents)
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1269
     and lets the appropriate reader read the file.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1270
     To do this, the stream must be positionable.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1271
     Return nil (or whatever a handler returned), 
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1272
     if the stream does not contain an appropriate image."
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1273
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  1274
    |image|
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1275
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1276
    "
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1277
     ask all readers if they know
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1278
     this format ...
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1279
    "
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1280
    FileFormats do:[:readerClass |
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1281
	readerClass notNil ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1282
	    image := readerClass fromStream:aStream.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1283
	    image notNil ifTrue:[^ image].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1284
	]
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1285
    ].
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1286
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1287
    "
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1288
     nope - unknown format
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1289
    "
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1290
"/    'Image [info]: unknown image file format in stream: ' infoPrintCR.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1291
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1292
    ^ ImageNotFoundQuerySignal
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1293
		raiseRequestWith:aStream
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1294
		errorString:('IMAGE: unknown image file format in stream').
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1295
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1296
    "
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1297
     Image fromFile:'bitmaps/dano.tiff'
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1298
     Image fromFile:'bitmaps/test.fax'
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1299
     Image fromFile:'bitmaps/voice.tiff'
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1300
     Image fromFile:'voice.tiff'
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1301
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1302
     Image fromFile:'../fileIn/bitmaps/claus.gif'
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1303
     Image fromFile:'../fileIn/bitmaps/garfield.gif'
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1304
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1305
     Image fromFile:'../fileIn/bitmaps/founders.im8'
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1306
     Image fromFile:'../goodies/faces/next.com/steve.face'
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1307
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1308
     Image fromFile:'/LocalLibrary/Images/OS2/dos3.ico'
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1309
     Image fromFile:'bitmaps/globe1.xbm'
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1310
     Image fromFile:'bitmaps/globe1.xbm.Z'
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1311
     Image fromFile:'bitmaps/hello_world.icon'
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1312
    "
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1313
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1314
    "Created: 13.9.1996 / 18:06:00 / cg"
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1315
    "Modified: 1.2.1997 / 14:48:41 / cg"
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1316
!
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1317
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1318
fromStream:aStream using:aReaderClass
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1319
    "read an image from a stream, given an imageReaderClass.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1320
     Use this, if you know the files format, but it has an invalid
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1321
     extension (or non-definite header), so #fromStream: could not
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1322
     find out the images format.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1323
     Return nil (or whatever a handler returned), 
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1324
     if the stream does not contain an appropriate image."
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1325
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1326
    |image|
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1327
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1328
    image := aReaderClass fromStream:aStream.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1329
    image notNil ifTrue:[^ image].
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1330
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1331
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1332
     nope - unknown format
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1333
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1334
"/    'Image [info]: unknown image file format in stream: ' infoPrintCR.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1335
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1336
    ^ ImageNotFoundQuerySignal
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1337
		raiseRequestWith:aStream
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1338
		errorString:('IMAGE: unknown image file format in stream').
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1339
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1340
    "Created: 1.2.1997 / 14:46:20 / cg"
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1341
    "Modified: 1.2.1997 / 14:48:53 / cg"
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1342
! !
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1343
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  1344
!Image class methodsFor:'misc'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1345
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1346
ditherAlgorithm
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1347
    "return the way we dither - 
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1348
	#threshold, or nil        -> no dither
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1349
	#pattern, or #ordered     -> orderedDither (ugly, but fast)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1350
	#error or #floydSteinberg -> errorDiffusion; much better
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1351
	#burkes                   -> errorDiffusion; even better."
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1352
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1353
    ^ DitherAlgorithm
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1354
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1355
    "Created: 17.6.1996 / 18:57:47 / cg"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1356
!
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1357
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1358
ditherAlgorithm:aSymbol
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1359
    "define how to dither - 
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1360
	#threshold, or nil        -> no dither
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1361
	#pattern, or #ordered     -> orderedDither (ugly, but fast)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1362
	#error or #floydSteinberg -> errorDiffusion; much better
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1363
	#burkes                   -> errorDiffusion; even better."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1364
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1365
    DitherAlgorithm := aSymbol
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1366
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1367
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1368
     Image dither:#pattern
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1369
     Image dither:#floydSteinberg
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1370
     Image dither:#burkes
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1371
     Image dither:nil
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1372
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1373
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1374
    "Modified: 10.6.1996 / 12:27:09 / cg"
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1375
    "Created: 17.6.1996 / 18:57:19 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1376
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1377
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1378
numberOfDitherColors:n
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1379
    "define how many colors (i.e. patterns) to use when
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1380
     doing a pattern dither"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1381
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1382
    NumberOfDitherColors := n
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1383
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1384
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1385
orderedDitherMatrixOfSize:sz
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1386
    sz == 2 ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1387
	^ #[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1388
		0 2 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1389
		3 1
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1390
	   ].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1391
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1392
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1393
    sz == 4 ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1394
	^ #[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1395
		 0  8  2 10
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1396
		12  4 14  6
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1397
		 3 11  1  9
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1398
		15  7 13  5
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1399
	   ].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1400
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1401
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1402
    sz == 8 ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1403
	^  #[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1404
		0 32  8 40    2 34 10 42
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1405
	       48 16 56 24   50 18 58 26
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1406
	       12 44  4 36   14 46  6 38    
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1407
	       60 28 52 20   62 30 54 22
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1408
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1409
		3 35 11 43    1 33  9 41
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1410
	       51 19 59 27   49 17 57 25
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1411
	       15 47  7 39   13 45  5 37    
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1412
	       63 31 55 23   61 29 53 21
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1413
	    ].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1414
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1415
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1416
    ^ nil
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1417
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1418
    "Created: 7.6.1996 / 14:15:05 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1419
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1420
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  1421
!Image class methodsFor:'queries'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1422
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1423
defaultPhotometric
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1424
    "return the default photometric pixel interpretation"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1425
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1426
    ^ #blackIs0
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1427
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1428
    "Modified: 20.4.1996 / 23:40:41 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1429
    "Created: 10.6.1996 / 18:08:12 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1430
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1431
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1432
imageDepth
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1433
    "return the depth of images represented by instances of
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1434
     this class.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1435
     Must be redefined in concrete subclasses"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1436
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1437
    ^ self shouldNotImplement
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1438
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1439
    "Modified: 20.4.1996 / 23:40:41 / cg"
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1440
!
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1441
1306
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  1442
imageFileSuffixes
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  1443
    "return a collection of suffixes which are recognized as image-file suffix"
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  1444
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  1445
    ^ FileFormats keys
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  1446
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  1447
    "
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  1448
     Image imageFileSuffixes
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  1449
    "
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  1450
!
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  1451
1572
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  1452
imageReaderClassForSuffix:aSuffix
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  1453
    "return an appropriate imageReader class for a given file-suffix"
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  1454
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  1455
    ^ FileFormats at:(aSuffix asLowercase) ifAbsent:nil.
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  1456
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  1457
    "
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  1458
     Image imageReaderClassForSuffix:'tiff'
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  1459
    "
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  1460
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
  1461
    "Modified: 10.4.1997 / 17:36:37 / cg"
1572
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  1462
!
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  1463
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  1464
implementorForDepth:depth
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1465
    "return the class, which best implements images of depth"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1466
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1467
    depth == 1 ifTrue:[^ Depth1Image].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1468
    depth == 2 ifTrue:[^ Depth2Image].
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  1469
    depth <= 4 ifTrue:[^ Depth4Image].
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  1470
    depth <= 8 ifTrue:[^ Depth8Image].
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  1471
    depth <= 16 ifTrue:[^ Depth16Image].
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  1472
    depth <= 24 ifTrue:[^ Depth24Image].
1664
42b1af0353c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1662
diff changeset
  1473
    depth <= 32 ifTrue:[^ Depth32Image].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1474
    ^ self
1664
42b1af0353c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1662
diff changeset
  1475
42b1af0353c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1662
diff changeset
  1476
    "Modified: 24.4.1997 / 19:04:52 / cg"
1611
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1477
!
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1478
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1479
isImageFileSuffix:aSuffix
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1480
    "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
  1481
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1482
     ^ self imageFileSuffixes includes:(aSuffix asLowercase)
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1483
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1484
    "
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1485
     Image isImageFileSuffix:'gif'
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1486
     Image isImageFileSuffix:'xbm'
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1487
     Image isImageFileSuffix:'foo'
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1488
    "
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1489
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1490
    "Created: 18.4.1997 / 14:55:28 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1491
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1492
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  1493
!Image class methodsFor:'screen capture'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1494
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1495
fromScreen
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1496
    "return an image of the full screen.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1497
     WARNING: this temporarily grabs the display
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1498
	      it may not work from within a buttonMotion
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1499
	      (use #fromScreen:on:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1500
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1501
    |display|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1502
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1503
    display := Screen current.
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1504
    ^ self 
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1505
	fromScreen:(0@0 corner:(display width @ display height))
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1506
	on:display
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1507
	grab:true
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1508
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1509
    "
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1510
     Image fromScreen
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1511
     Image fromScreen inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1512
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1513
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1514
    "Modified: 26.3.1997 / 10:44:55 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1515
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1516
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1517
fromScreen:aRectangle
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1518
    "return an image of a part of the screen.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1519
     WARNING: this temporarily grabs the display
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1520
	      it may not work from within a buttonMotion
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1521
	      (use #fromScreen:on:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1522
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1523
    ^ self 
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1524
	fromScreen:aRectangle 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1525
	on:Screen current
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1526
	grab:true
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1527
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1528
    "
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1529
     Image fromScreen:(0@0 corner:100@100)
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1530
     (Image fromScreen:(0@0 corner:100@100)) inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1531
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1532
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1533
    "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
  1534
!
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1535
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1536
fromScreen:aRectangle on:aDevice
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1537
    "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
  1538
     another display device.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1539
     WARNING: this temporarily grabs the display
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1540
	      it may not work from within a buttonMotion
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1541
	      (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
  1542
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1543
    ^ self
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1544
	fromScreen:aRectangle 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1545
	on:aDevice 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1546
	grab:true
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1547
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1548
    "
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1549
     Image fromScreen:(0@0 corner:100@100)
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1550
    "
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1551
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1552
    "get a snapshot of your friends screen ...
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1553
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1554
     |dpy2|
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1555
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1556
     dpy2 := XWorkstation new initializeFor:'idefix:0'.
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1557
     (Image fromScreen:(dpy2 bounds) on:dpy2) inspect
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1558
    "
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1559
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1560
    "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
  1561
!
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1562
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1563
fromScreen:aRectangle on:aDisplay grab:doGrab
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1564
    "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
  1565
     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
  1566
     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
  1567
     shown while the readout is done.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1568
     WARNING: with doGrab true, this temporarily grabs the display
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1569
	      and it may not work from within a buttonMotion
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1570
	      (use with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1571
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1572
    |depth vis img|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1573
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1574
    depth := aDisplay depth.
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1575
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1576
    "/
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1577
    "/ 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
  1578
    "/ (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
  1579
    "/  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
  1580
    "/
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1581
    vis := aDisplay visualType.
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1582
    (vis == #TrueColor or:[vis == #DirectColor]) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1583
	depth > 8 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1584
	    depth := 24.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1585
	]
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1586
    ].
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1587
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1588
    img := (self implementorForDepth: depth) new.
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1589
    ^ img fromScreen:aRectangle on:aDisplay grab:doGrab
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1590
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1591
    "Modified: 26.3.1997 / 10:44:39 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1592
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1593
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1594
fromScreenArea
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1595
    "return an image of a part of the screen; 
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1596
     let user specify screen area.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1597
     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
  1598
     Use #fromUser for ST-80 compatibility.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1599
     WARNING: this temporarily grabs the display
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1600
	      it may not work from within a buttonMotion
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1601
	      (use #fromScreen:on:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1602
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1603
    ^ self fromScreen:(Rectangle fromUser)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1604
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1605
    "
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1606
     Image fromScreenArea
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1607
     Image fromScreenArea inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1608
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1609
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1610
    "Modified: 26.3.1997 / 10:45:17 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1611
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1612
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1613
fromUser
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1614
    "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
  1615
     Same as fromScreenArea, for ST-80 compatibility.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1616
     WARNING: this temporarily grabs the display
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1617
	      it may not work from within a buttonMotion
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1618
	      (use #fromScreen:on:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1619
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1620
    ^ self fromScreenArea
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1621
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1622
    "
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1623
     Image fromUser
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1624
     Image fromUser inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1625
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1626
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1627
    "Modified: 26.3.1997 / 10:45:25 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1628
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1629
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1630
fromView:aView
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1631
    "return an image taken from a views contents as currently
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1632
     on the screen. The returned image has the same depth and photometric
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1633
     as the Display. 
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1634
     Notice, that for invisible or partial covered views, 
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1635
     the returned Image is NOT correct. 
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1636
     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
  1637
     WARNING: this temporarily grabs the display
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1638
	      it may not work from within a buttonMotion
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1639
	      (use #fromView:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1640
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1641
    ^ self
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1642
	fromView:aView 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1643
	grab:true
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1644
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1645
    "
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1646
     Image fromView:(Launcher allInstances first window topView)
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1647
     Image fromView:(BrowserView allInstances first topView)
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1648
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1649
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1650
    "get a snapshot from whichever view is active:
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1651
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1652
     |active|
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1653
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1654
     active := WindowGroup activeGroup topViews first.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1655
     (Image fromView:active) inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1656
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1657
1043
0688425d02c9 Rename Launcher-->OldLauncher, NewLauncher-->Launcher.
Stefan Vogel <sv@exept.de>
parents: 1041
diff changeset
  1658
    "Modified: 9.9.1996 / 22:41:01 / stefan"
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1659
    "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
  1660
!
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1661
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1662
fromView:aView grab:doGrab
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1663
    "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
  1664
     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
  1665
     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
  1666
     shown while the readout is done.
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1667
     The returned image has the same depth and photometric
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1668
     as the Display. 
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1669
     Notice, that for invisible or partial covered views, 
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1670
     the returned Image is NOT correct. 
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1671
     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
  1672
     WARNING: with doGrab true, this temporarily grabs the display
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1673
	      and it may not work from within a buttonMotion
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1674
	      (use with a false grabArg then)."
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1675
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1676
    |org dev|
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1677
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1678
    dev := aView graphicsDevice.
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1679
    org := dev translatePoint:(0@0)
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1680
			 from:(aView id)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1681
			   to:dev rootWindowId.
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1682
    ^ self fromScreen:(org extent:aView extent) on:dev grab:doGrab
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1683
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1684
    "Created: 26.3.1997 / 10:34:20 / cg"
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1685
    "Modified: 26.3.1997 / 10:45:50 / cg"
157
claus
parents: 154
diff changeset
  1686
! !
claus
parents: 154
diff changeset
  1687
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  1688
!Image methodsFor:'ST-80 compatibility'!
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  1689
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  1690
asCachedImage
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  1691
    "return the receiver associated to the current screens device.
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  1692
     For ST-80 compatibility 
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  1693
     (ST/X uses Image for both device- and nonDevice-images)"
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  1694
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  1695
    ^ self on:Screen current
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  1696
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  1697
    "Modified: 23.4.1996 / 11:10:32 / cg"
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  1698
!
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  1699
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  1700
asRetainedMedium
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  1701
    "return the receiver associated to the current screens device.
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  1702
     For ST-80 compatibility 
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  1703
     (ST/X uses Image for both device- and nonDevice-images)"
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  1704
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  1705
    ^ self on:Screen current
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  1706
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  1707
    "Modified: 23.4.1996 / 11:10:32 / cg"
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  1708
    "Created: 27.1.1997 / 15:49:08 / cg"
1325
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  1709
!
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  1710
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  1711
bounds:newBounds
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  1712
    ^ self
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  1713
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  1714
    "Created: 10.2.1997 / 12:44:46 / cg"
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  1715
!
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  1716
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1717
containsPoint:aPoint
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1718
    "in st-80, images are visualComponents ..."
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1719
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1720
    ^ self bounds containsPoint:aPoint
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1721
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1722
    "Created: 6.3.1997 / 15:24:12 / cg"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1723
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1724
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  1725
convertToPalette:aColormap renderedBy:anImageRenderer
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  1726
    "this does not really mimicri the corresponding ST-80 functionality"
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  1727
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  1728
    |monoBits convertedImage|
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  1729
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  1730
    aColormap size == 2 ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1731
	anImageRenderer class == OrderedDither ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1732
	    monoBits := self orderedDitheredMonochromeBits.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1733
	] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1734
	    monoBits := self floydSteinbergDitheredMonochromeBits.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1735
	].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1736
	(((aColormap at:1) = Color black)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1737
	and:[(aColormap at:2) = Color white]) ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1738
	    "/ ok
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1739
	] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1740
	    (((aColormap at:1) = Color white)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1741
	    and:[(aColormap at:2) = Color black]) ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1742
		monoBits invert
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1743
	    ]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1744
	].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1745
	convertedImage := Depth1Image width:width height:height fromArray:monoBits.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1746
	convertedImage palette:aColormap.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1747
	^ convertedImage
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  1748
    ].
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  1749
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  1750
    self error:'unimplemented operation'.
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  1751
    ^ self
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  1752
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  1753
    "Modified: 1.3.1997 / 17:25:50 / cg"
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  1754
!
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  1755
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1756
paintBasis
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1757
    "huh - whats that;
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1758
     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
  1759
     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
  1760
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1761
    ^ ColorValue
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1762
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1763
    "Created: 6.3.1997 / 15:24:19 / cg"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1764
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1765
1325
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  1766
preferredBounds
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  1767
    ^ self bounds
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  1768
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  1769
    "Created: 10.2.1997 / 12:42:36 / cg"
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  1770
! !
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  1771
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  1772
!Image methodsFor:'accessing'!
48194c26a46c Initial revision
claus
parents:
diff changeset
  1773
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1774
bitsPerSample
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1775
    "return the number of bits per sample.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1776
     The return value is an array of bits-per-plane."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1777
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1778
    bitsPerSample notNil ifTrue:[^ bitsPerSample].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1779
    ^ Array with:self depth
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1780
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1781
    "Modified: 10.6.1996 / 18:04:21 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1782
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1783
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1784
colorMap
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1785
    "return the colormap"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1786
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1787
    ^ colorMap
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1788
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1789
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1790
colorMap:aColorMap
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1791
    "set the colorMap; this also set the photometric to a useful defualt."
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1792
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1793
    |sz "{ Class: SmallInteger }"
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1794
     sameColors|
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1795
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1796
    (aColorMap isNil and:[colorMap isNil]) ifTrue:[^ self].
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1797
    photometric == #palette ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1798
	"/ any change at all ?
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1799
	(sz := aColorMap size) == colorMap size ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1800
	    sameColors := true.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1801
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1802
	    1 to:sz do:[:idx |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1803
		(aColorMap at:idx) = (colorMap at:idx) ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1804
		    sameColors := false.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1805
		]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1806
	    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1807
	    sameColors ifTrue:[^ self].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1808
	]
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1809
    ].
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1810
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1811
    colorMap := aColorMap.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1812
    colorMap notNil ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1813
	photometric := #palette.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1814
    ] ifFalse:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1815
	(photometric == #palette) ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1816
	    photometric := #blackIs0
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1817
	]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1818
    ].
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1819
    deviceForm notNil ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1820
	self release
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1821
    ]
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1822
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1823
    "Modified: 31.8.1995 / 03:05:59 / claus"
1446
3007549e3d5e never convert a colorArray to a colorMap
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
  1824
    "Modified: 7.3.1997 / 21:24:23 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1825
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1826
757
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  1827
container:aVisualContainer
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  1828
    "ignored here - added to allow images to be used like
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  1829
     VisualComponents (later, Image should inherit from it)"
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  1830
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  1831
    "Created: 28.5.1996 / 23:43:49 / cg"
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  1832
    "Modified: 29.5.1996 / 10:22:23 / cg"
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  1833
!
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  1834
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1835
depth
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1836
    "return the depth of the image"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1837
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1838
    ^ self bitsPerPixel
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1839
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1840
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1841
device
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1842
    "return the device, the receiver is associated with.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1843
     Return nil, if the image is unassigned."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1844
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1845
    ^ device
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1846
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1847
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1848
extent
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1849
    "return the images extent"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1850
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1851
    ^ width@height
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1852
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1853
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1854
fullColorId
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1855
    "return the id of the full color image on the device.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1856
     Return nil, if the image is unassigned."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1857
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1858
    fullColorDeviceForm isNil ifTrue:[^ nil].
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1859
    ^ fullColorDeviceForm id
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1860
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1861
728
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  1862
graphicsDevice
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  1863
    "same as #device - for ST-80 compatibility"
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  1864
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  1865
    ^ device
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  1866
!
744
db883c9b74b8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 728
diff changeset
  1867
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1868
height
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1869
    "return the height of the image"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1870
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1871
    ^ height
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1872
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1873
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1874
id
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1875
    "return the id of the image on the device.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1876
     Return nil, if the image is unassigned."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1877
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1878
    deviceForm isNil ifTrue:[^ nil].
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1879
    ^ deviceForm id
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1880
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1881
896
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  1882
mask
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  1883
    ^ mask
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  1884
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  1885
    "Created: 21.6.1996 / 12:57:44 / cg"
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  1886
!
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  1887
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  1888
mask:anotherImage
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  1889
    "set the images mask - currently, this may be nil or a Depth1Image.
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  1890
     (it is planned to support alpha information in a Depth8 maskImage in
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  1891
      the near future).
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  1892
     For depth1 masks: each pixel of the image where a corresponding
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1893
		       1-bit is present in the mask will be drawn;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1894
		       0-bit mask pixels lead to transparent pixels.
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  1895
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  1896
     For depth8 masks: (future):
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1897
		       each pixel specifies the alpha value (0..255),
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1898
		       which specifies the transparency of that pixel.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1899
		       0 means completely transparent, 255 means completely
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1900
		       opaque. The 1-plane mask is a special case of this,
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1901
		       interpreting a 0 as a 0 alpha value and 1's as an
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  1902
		       alpha value of 255."
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  1903
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  1904
    mask := anotherImage.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  1905
    maskedPixelsAre0 := false.
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  1906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  1907
    "Created: 27.6.1996 / 17:45:22 / cg"
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  1908
    "Modified: 12.4.1997 / 12:04:39 / cg"
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  1909
!
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  1910
1587
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  1911
maskedPixelsAre0
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  1912
    "return true if masked pixels have been cleared to zero"
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  1913
1594
07084da1ce20 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1593
diff changeset
  1914
    maskedPixelsAre0 isNil ifTrue:[^ false].
1587
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  1915
    ^ maskedPixelsAre0
1594
07084da1ce20 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1593
diff changeset
  1916
07084da1ce20 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1593
diff changeset
  1917
    "Modified: 14.4.1997 / 17:20:52 / cg"
1587
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  1918
!
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  1919
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  1920
maskedPixelsAre0:aBoolean
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  1921
    "set/clear the flag which states if masked pixels
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  1922
     have been set to zero. Knowing this to be true allows
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  1923
     faster drawing of the image later; (however, not setting
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  1924
     it will still produce correct output).
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  1925
     This flag is typically set by image readers."
1587
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  1926
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  1927
    maskedPixelsAre0 := aBoolean
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  1928
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  1929
    "Modified: 12.4.1997 / 12:08:42 / cg"
1587
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  1930
!
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  1931
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1932
monochromeId
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1933
    "return the id of the monochrome image on the device.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1934
     Return nil, if the image is unassigned."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1935
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1936
    monoDeviceForm isNil ifTrue:[^ nil].
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1937
    ^ monoDeviceForm id
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1938
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1939
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1940
palette 
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1941
    "return the colormap; ST-80 compatibility"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1942
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1943
    ^ colorMap
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1944
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1945
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1946
palette:aColormap 
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1947
    "set the colormap; ST-80 compatibility"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1948
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1949
    self colorMap:aColormap
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1950
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1951
    "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
  1952
    "Modified: 8.6.1996 / 09:54:02 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1953
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1954
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1955
photometric
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1956
    "return the photometric, a symbol such as #palette, #rgb etc."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1957
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1958
    ^ photometric
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1959
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1960
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1961
samplesPerPixel
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1962
    "return the number of samples per pixel in the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1963
     The return value is an array of bits-per-plane."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1964
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1965
    samplesPerPixel notNil ifTrue:[^ samplesPerPixel].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1966
    ^ 1
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1967
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1968
    "Modified: 10.6.1996 / 18:03:30 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1969
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1970
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1971
width
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1972
    "return the width of the image"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1973
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1974
    ^ width
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1975
! !
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1976
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1977
!Image methodsFor:'accessing - pixels'!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  1978
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  1979
at:aPoint
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  1980
    "WARNING: for now, this returns a pixels color 
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  1981
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  1982
     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
  1983
     Use #colorAt: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  1984
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  1985
     retrieve the pixel at aPoint; return a color.
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  1986
     Pixels start at 0@0 for upper left pixel, end at
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  1987
     (width-1)@(height-1) for lower right pixel.
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  1988
     You should not use this method for image-processing, its
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  1989
     very slow ...
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  1990
     (it is meant to access individual pixels - for example, in a bitmap editor)"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  1991
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  1992
    'Image [warning]: the Image>>at: will change semantics soon' infoPrintCR.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  1993
    ^ self colorAtX:(aPoint x) y:(aPoint y)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  1994
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  1995
    "Modified: 24.4.1997 / 17:31:40 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  1996
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  1997
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1998
at:aPoint put:aColor
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  1999
    "WARNING: for now, this expects a pixels color 
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2000
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2001
     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
  2002
     Use #colorAt:put: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2003
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2004
     set the pixel at aPoint to aColor.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2005
     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
  2006
     (width-1)@(height-1) for lower right pixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2007
     You should not use this method for image-processing, its
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2008
     very slow ...
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2009
     (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
  2010
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2011
    'Image [warning]: the Image>>at:put: will change semantics soon' infoPrintCR.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2012
    ^ self atX:aPoint x y:aPoint y put:aColor
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2013
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2014
    "Modified: 24.4.1997 / 17:31:59 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2015
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2016
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2017
atPoint:aPoint
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2018
    "ST-80 compatibility: return the pixelValue at:aPoint."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2019
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2020
    ^ self pixelAtX:aPoint x y:aPoint y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2021
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2022
    "Modified: 24.4.1997 / 16:18:44 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2023
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2024
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2025
atPoint:aPoint put:aPixelValue
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2026
    "ST-80 compatibility: set the pixelValue at:aPoint."
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2027
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2028
    ^ self pixelAtX:aPoint x y:aPoint y put:aPixelValue
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2029
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2030
    "Modified: 24.4.1997 / 17:17:59 / cg"
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2031
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2032
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2033
atX:x y:y
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2034
    "WARNING: for now, this returns a pixels color 
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2035
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2036
     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
  2037
     Use #colorAt: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2038
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2039
     Retrieve a pixel at x/y; return a color.
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2040
     Pixels start at 0@0 for upper left pixel, end at
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2041
     (width-1)@(height-1) for lower right pixel.
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2042
     You should not use this method for image-processing, its
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2043
     very slow ...
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2044
     (it is meant to access individual pixels - for example, in a bitmap editor)"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2045
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2046
    'Image [warning]: the Image>>atX:y: will change semantics soon' infoPrintCR.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2047
    ^ self colorAtX:x y:y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2048
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2049
    "Modified: 24.4.1997 / 17:28:37 / cg"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2050
!
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2051
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2052
atX:x y:y put:aColor
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2053
    "WARNING: for now, this expects a pixels color 
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2054
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2055
     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
  2056
     Use #colorAt:put: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2057
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2058
     set the pixel at x/y to aColor.
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2059
     Pixels start at 0@0 for the upper left pixel, end at
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2060
     (width-1)@(height-1) for the lower right pixel.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2061
     This method checks if the color can be stored in the image.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2062
     (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
  2063
     You should not use this method for image-processing, it is very slow ...
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2064
     (it is meant to access individual pixels - for example, in a bitmap editor)"
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2065
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2066
    'Image [warning]: the Image>>atX:y:put: will change semantics soon' infoPrintCR.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2067
    ^ self colorAtX:x y:y put:aColor
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2068
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2069
    "Modified: 24.4.1997 / 17:30:48 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2070
!
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2071
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2072
atX:x y:y putValue:aPixelValue
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2073
    "set the pixel at x/y to aPixelValue.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2074
     The interpretation of the pixelValue depends on the photometric
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2075
     and the colormap. (see also: Image>>atX:y:put:)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2076
     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
  2077
     (width-1) @ (height-1) for the lower right pixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2078
     You should not use this method for image-processing, its
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2079
     very slow ...
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2080
     (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
  2081
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2082
    self obsoleteMethodWarning:'use #pixelAtX:y:put:'.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2083
    ^ self pixelAtX:x y:y put:aPixelValue.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2084
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2085
    "Modified: 24.4.1997 / 17:15:45 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2086
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2087
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2088
bits
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2089
    "return the raw image data; depending on the photometric,
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2090
     this has to be interpreted as monochrome, greyscale,
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2091
     palette or rgb data. It is also packed to be dense, so
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2092
     a 4 bitPerSample palette image will store 2 pixels per byte."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2093
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2094
    ^ bytes
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2095
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2096
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2097
colorAt:aPoint
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2098
    "retrieve a pixel at x/y; return a color.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2099
     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
  2100
     (width-1)@(height-1) for lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2101
     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
  2102
     very slow ...
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2103
     (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
  2104
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2105
    ^ self colorAtX:(aPoint x) y:(aPoint y)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2106
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2107
    "Created: 24.4.1997 / 17:02:31 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2108
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2109
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2110
colorAtX:x y:y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2111
    "retrieve a pixel at x/y; return a color.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2112
     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
  2113
     (width-1)@(height-1) for lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2114
     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
  2115
     very slow ...
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2116
     (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
  2117
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2118
    |pixel|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2119
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2120
    pixel := self pixelAtX:x y:y.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2121
    ^ self colorFromValue:pixel
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2122
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2123
    "Modified: 24.4.1997 / 16:18:53 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2124
    "Created: 24.4.1997 / 17:00:52 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2125
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2126
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2127
colorAtX:x y:y put:aColor
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2128
    "set the pixel at x/y to aColor.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2129
     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
  2130
     (width-1)@(height-1) for the lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2131
     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
  2132
     (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
  2133
     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
  2134
     (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
  2135
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2136
    |pixel|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2137
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2138
    pixel := self valueFromColor:aColor.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2139
    self pixelAtX:x y:y put:pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2140
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2141
    "Modified: 24.4.1997 / 17:36:20 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2142
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2143
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2144
data
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2145
    "for backward compatibility - will vanish"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2146
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2147
    self obsoleteMethodWarning:'use #bits'.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2148
    ^ bytes
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2149
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2150
    "Modified: 24.4.1997 / 17:37:57 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2151
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2152
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2153
data:aByteArray
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2154
    "for backward compatibility - will vanish"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2155
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2156
    self obsoleteMethodWarning.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2157
    bytes := aByteArray
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2158
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2159
    "Modified: 24.4.1997 / 17:38:18 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2160
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2161
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2162
pixelAtX:x y:y
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2163
    "retrieve the pixelValue at aPoint; return an integer number.
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2164
     Pixels start at 0/0 for upper left pixel, and end at
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2165
     width-1@height-1 for lower right pixel.
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2166
     The returned numbers interpretation depends on the photometric
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2167
     and the colormap. (see also Image>>at: and Image>>atX:y:)
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2168
     You should not use this method for image-processing of
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2169
     big images, its very slow ... 
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2170
     (it is meant to access individual pixels - for example, in a bitmap editor)"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2171
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2172
    ^ self subclassResponsibility
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2173
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2174
    "Created: 24.4.1997 / 16:06:56 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2175
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2176
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2177
pixelAtX:x y:y put:aPixelValue
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2178
    "set the pixel at x/y to aPixelValue.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2179
     The interpretation of the pixelValue depends on the photometric
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2180
     and the colormap. (see also: Image>>atX:y:put:)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2181
     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
  2182
     (width-1) @ (height-1) for the lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2183
     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
  2184
     very slow ...
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2185
     (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
  2186
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2187
    ^ self subclassResponsibility
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2188
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2189
    "Created: 24.4.1997 / 17:05:11 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2190
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2191
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2192
rowAt:rowIndex
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2193
    "retrieve an array filled with pixel values from
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2194
     a single row.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2195
     Notice: row indexing starts at 0.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2196
     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
  2197
     concrete image subclasses should redefine this for more performance."
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2198
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2199
    |pixelArray|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2200
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2201
    pixelArray := self pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2202
    self rowAt:rowIndex into:pixelArray startingAt:1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2203
    ^ pixelArray
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2204
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2205
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2206
     |i|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2207
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2208
     i := Image fromFile:'bitmaps/gifImages/garfield.gif'.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2209
     (i rowAt:0) inspect
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2210
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2211
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2212
     |i|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2213
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2214
     i := Image fromFile:'bitmaps/SBrowser.xbm'.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2215
     (i rowAt:0) inspect
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2216
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2217
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2218
    "Modified: 24.4.1997 / 15:51:24 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2219
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2220
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2221
rowAt:rowIndex into:aPixelBuffer
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2222
    "fill aBuffer with pixel values retrieved from a single row.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2223
     Notice: row indexing starts at 0."
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2224
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2225
    ^ self rowAt:rowIndex into:aPixelBuffer startingAt:1
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2226
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2227
    "Created: 24.4.1997 / 15:44:46 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2228
    "Modified: 24.4.1997 / 15:51:35 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2229
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2230
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2231
rowAt:rowIndex into:aPixelBuffer startingAt:startIndex
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2232
    "fill aBuffer with pixel values retrieved from a single row.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2233
     Notice: row indexing starts at 0.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2234
     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
  2235
     concrete image subclasses should redefine this for more performance."
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2236
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2237
    |w "{ Class: SmallInteger }"|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2238
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2239
    w := width-1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2240
    0 to:w do:[:col |
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2241
        aPixelBuffer at:(col + startIndex) put:(self pixelAtX:col y:rowIndex)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2242
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2243
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2244
    "Created: 24.4.1997 / 15:05:21 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2245
    "Modified: 24.4.1997 / 16:52:43 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2246
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2247
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2248
rowAt:rowIndex putAll:pixelArray
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2249
    "store a single rows pixels from bits in the argument;
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2250
     Notice: row indexing starts at 0.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2251
     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
  2252
     concrete image subclasses should redefine this for more performance."
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2253
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2254
    ^ self rowAt:rowIndex putAll:pixelArray startingAt:1
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2255
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2256
    "Modified: 24.4.1997 / 15:51:58 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2257
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2258
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2259
rowAt:rowIndex putAll:pixelArray startingAt:startIndex
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2260
    "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
  2261
     return the pixelArray.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2262
     Notice: row indexing starts at 0.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2263
     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
  2264
     concrete image subclasses should redefine this for more performance."
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2265
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2266
    |w "{ Class: SmallInteger }"|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2267
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2268
    w := width-1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2269
    0 to:w do:[:col |
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2270
        self pixelAtX:col y:rowIndex put:(pixelArray at:(col + startIndex))
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2271
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2272
    ^ pixelArray
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2273
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2274
    "Modified: 24.4.1997 / 17:05:57 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2275
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2276
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2277
valueAt:aPoint
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2278
    "WARNING: for now, this returns a pixels value 
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2279
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2280
     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
  2281
     Use #pixelAt: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2282
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2283
     Retrieve the pixelValue at aPoint; return an integer number.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2284
     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
  2285
     width-1@height-1 for lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2286
     The returned numbers interpretation depends on the photometric
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2287
     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
  2288
     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
  2289
     very slow ...
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2290
     (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
  2291
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2292
    'Image [warning]: the Image>>valueAt: will change semantics soon' infoPrintCR.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2293
    ^ self pixelAtX:aPoint x y:aPoint y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2294
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2295
    "Modified: 24.4.1997 / 17:28:16 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2296
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2297
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2298
valueAtX:x y:y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2299
    "WARNING: for now, this returns a pixels value 
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2300
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2301
     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
  2302
     Use #pixelAt: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2303
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2304
     Retrieve the pixelValue at aPoint; return an integer number.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2305
     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
  2306
     width-1@height-1 for lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2307
     The returned numbers interpretation depends on the photometric
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2308
     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
  2309
     You should not use this method for image-processing of
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2310
     big images, its very slow ... 
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2311
     (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
  2312
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2313
    'Image [warning]: the Image>>valueAtX:y: will change semantics soon' infoPrintCR.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2314
    ^ self pixelAtX:x y:y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2315
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2316
    "Modified: 24.4.1997 / 17:12:49 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2317
! !
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2318
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2319
!Image methodsFor:'accessing - private'!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2320
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2321
bits:aByteArray
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2322
    "set the raw data.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2323
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2324
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2325
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2326
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2327
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2328
    bytes := aByteArray
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2329
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2330
    "Modified: 23.4.1996 / 11:08:28 / cg"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2331
!
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2332
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2333
bitsPerSample:aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2334
    "set the number of bits per sample. 
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2335
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2336
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2337
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2338
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2339
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2340
    bitsPerSample := aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2341
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2342
    "Modified: 23.4.1996 / 11:08:31 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2343
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2344
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2345
depth:d
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2346
    "set the depth of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2347
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2348
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2349
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2350
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2351
1362
454d644f6ff7 set depth & bitsPerPixel for ST-80 compatibility.
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
  2352
    depth := self depth.
454d644f6ff7 set depth & bitsPerPixel for ST-80 compatibility.
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
  2353
    bitsPerPixel := d.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2354
    d == 24 ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2355
	samplesPerPixel := 3.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2356
	bitsPerSample := #(8 8 8)
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2357
    ] ifFalse:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2358
	samplesPerPixel := 1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2359
	bitsPerSample := Array with:d 
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2360
    ]
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2361
1362
454d644f6ff7 set depth & bitsPerPixel for ST-80 compatibility.
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
  2362
    "Modified: 20.2.1997 / 14:39:10 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2363
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2364
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2365
extent:anExtent
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2366
    "set the images extent.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2367
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2368
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2369
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2370
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2371
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2372
    width := anExtent x.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2373
    height := anExtent y
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2374
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2375
    "Modified: 23.4.1996 / 11:08:38 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2376
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2377
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2378
height:aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2379
    "set the height of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2380
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2381
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2382
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2383
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2384
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2385
    height := aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2386
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2387
    "Modified: 23.4.1996 / 11:08:40 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2388
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2389
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2390
photometric:aSymbol
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2391
    "set the photometric interpretation of the pixel values.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2392
     The argument, aSymbol is one of:
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2393
	#blackIs0, #whiteIs0, #palette, #rgb
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2394
     See TIFF documentation, from which the photometric concept is borrowed.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2395
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2396
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2397
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2398
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2399
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2400
    |b|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2401
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2402
    photometric := aSymbol.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2403
    bitsPerSample isNil ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2404
	photometric == #rgb ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2405
	    b := self class imageDepth // 3.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2406
	    bitsPerSample := Array with:b with:b with:b
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2407
	] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2408
	    bitsPerSample := Array with:(self class imageDepth)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2409
	].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2410
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2411
    samplesPerPixel isNil ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2412
	photometric == #rgb ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2413
	    samplesPerPixel := 3
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2414
	] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2415
	    samplesPerPixel := 1
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2416
	]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2417
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2418
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2419
    "Modified: 10.6.1996 / 18:21:29 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2420
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2421
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2422
samplesPerPixel:aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2423
    "set the array of samples per pixel.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2424
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2425
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2426
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2427
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2428
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2429
    samplesPerPixel := aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2430
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2431
    "Modified: 23.4.1996 / 11:08:45 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2432
!
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2433
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2434
width:aNumber
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2435
    "set the width of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2436
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2437
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2438
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2439
     existing image may confuse later pixel interpretation."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2440
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2441
    width := aNumber
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2442
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2443
    "Modified: 23.4.1996 / 11:08:48 / cg"
100
1b0b86c77397 co !!:*
claus
parents: 89
diff changeset
  2444
!
1b0b86c77397 co !!:*
claus
parents: 89
diff changeset
  2445
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2446
width:w height:h 
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2447
    "set the width and height of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2448
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2449
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2450
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2451
     existing image may confuse later pixel interpretation."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2452
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2453
    width := w.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2454
    height := h
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2455
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2456
    "Modified: 23.4.1996 / 11:08:53 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2457
!
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2458
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2459
width:w height:h depth:d
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2460
    "set the width, height and depth of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2461
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2462
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2463
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2464
     existing image may confuse later pixel interpretation."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2465
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2466
    width := w.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2467
    height := h.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2468
    self depth:d.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2469
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2470
    "Modified: 23.4.1996 / 11:08:56 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2471
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2472
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2473
width:w height:h depth:d fromArray:bits
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2474
    "set the width, height, depth and pixels of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2475
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2476
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2477
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2478
     existing image may confuse later pixel interpretation."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2479
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2480
    width := w.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2481
    height := h.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2482
    self depth:d.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2483
    bytes := bits
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2484
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2485
    "Modified: 23.4.1996 / 11:08:59 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2486
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2487
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2488
width:w height:h depth:d palette:aColormap
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2489
    "set the width, height and depth of the image.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2490
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2491
     This interface is only to be used when initializing
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2492
     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
  2493
     existing image may confuse later pixel interpretation."
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2494
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2495
    width := w.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2496
    height := h.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2497
    self depth:d.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2498
    colorMap := aColormap.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2499
    aColormap notNil ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2500
	photometric := #palette
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2501
    ]
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2502
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2503
    "Modified: 23.4.1996 / 11:08:56 / cg"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2504
    "Created: 6.3.1997 / 15:23:57 / cg"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2505
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2506
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2507
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
  2508
    "set all relevant internal state of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2509
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2510
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2511
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2512
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2513
894
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  2514
    ^ self
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2515
	width:w 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2516
	height:h 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2517
	photometric:p 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2518
	samplesPerPixel:spp 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2519
	bitsPerSample:bps 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2520
	colorMap:cm 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2521
	bits:pixels 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2522
	mask:nil
894
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  2523
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  2524
    "Modified: 20.6.1996 / 17:10:24 / cg"
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  2525
!
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  2526
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  2527
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
  2528
    "set all relevant internal state of the image.
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  2529
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  2530
     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
  2531
     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
  2532
     existing image may confuse later pixel interpretation."
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  2533
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2534
    width := w.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2535
    height := h.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2536
    photometric := p.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2537
    samplesPerPixel := spp.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2538
    bitsPerSample := bps.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2539
    colorMap := cm.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2540
    bytes := pixels.
894
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  2541
    mask := m.
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  2542
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2543
    "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
  2544
    "Created: 20.6.1996 / 17:09:53 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2545
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
  2546
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2547
!Image methodsFor:'binary storage'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2548
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2549
readBinaryContentsFrom: stream manager: manager
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2550
    "read a binary representation of an image from stream.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2551
     Redefined to flush any device data."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2552
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2553
    super readBinaryContentsFrom: stream manager: manager.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2554
    device := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2555
    deviceForm := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2556
    monoDeviceForm := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2557
    fullColorDeviceForm := nil.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2558
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  2559
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2560
storeBinaryDefinitionOn: stream manager: manager
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2561
    "store a binary representation of the receiver on stream.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2562
     This is an internal interface for binary storage mechanism.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2563
     Redefined to not store the device form (which is recreated at
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2564
     load time anyway)"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2565
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2566
    |tDevice tDeviceForm tMonoDeviceForm tFullColorDeviceForm|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2567
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2568
    tDevice := device.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2569
    tDeviceForm := deviceForm.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2570
    tMonoDeviceForm := monoDeviceForm.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2571
    tFullColorDeviceForm := fullColorDeviceForm.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2572
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2573
    device := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2574
    deviceForm := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2575
    monoDeviceForm := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2576
    fullColorDeviceForm := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2577
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2578
    super storeBinaryDefinitionOn: stream manager: manager.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2579
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2580
    device := tDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2581
    deviceForm := tDeviceForm.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2582
    monoDeviceForm := tMonoDeviceForm.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2583
    fullColorDeviceForm := tFullColorDeviceForm.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2584
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2585
    "Modified: 23.4.1996 / 09:30:50 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2586
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
  2587
48194c26a46c Initial revision
claus
parents:
diff changeset
  2588
!Image methodsFor:'converting'!
48194c26a46c Initial revision
claus
parents:
diff changeset
  2589
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2590
asBurkesDitheredMonochromeImage
837
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  2591
    "return a burkes dithered monochrome image from the receiver image.
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  2592
     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
  2593
     a floyd-steinberg dithered image.
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  2594
     Notice, that floyd-steinberg dithering is faster; both because less
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  2595
     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
  2596
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2597
    |monoBits|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2598
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2599
    monoBits := self burkesDitheredMonochromeBits.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2600
    ^ 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
  2601
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2602
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2603
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2604
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2605
     i := Image fromFile:'garfield.gif'.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2606
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2607
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2608
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2609
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2610
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2611
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2612
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2613
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2614
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2615
     i := Image fromFile:'claus.gif'.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2616
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2617
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2618
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2619
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2620
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2621
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2622
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2623
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2624
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2625
     i := Depth4Image
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2626
	     width:4 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2627
	     height:4
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2628
	     fromArray:#[ 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2629
			    16r01 16r23
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2630
			    16r45 16r67
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2631
			    16r89 16rab
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2632
			    16rcd 16ref 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2633
			].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2634
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2635
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2636
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2637
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2638
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2639
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2640
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2641
    "Created: 10.6.1996 / 12:34:44 / cg"
837
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  2642
    "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
  2643
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2644
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2645
asErrorDitheredMonochromeImage
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2646
    "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
  2647
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2648
    DitherAlgorithm == #burkes ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2649
	^ self asBurkesDitheredMonochromeImage
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2650
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2651
    DitherAlgorithm == #stevensonArce ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2652
	^ self asStevensonArgceDitheredMonochromeImage
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2653
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2654
    ^ self asFloydSteinbergDitheredMonochromeImage
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2655
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2656
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2657
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2658
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2659
     i := Image fromFile:'garfield.gif'.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2660
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2661
     i asErrorDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2662
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2663
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2664
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2665
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2666
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2667
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2668
     i := Image fromFile:'claus.gif'.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2669
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2670
     i asErrorDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2671
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2672
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2673
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2674
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2675
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2676
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2677
     i := Depth4Image
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2678
	     width:4 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2679
	     height:4
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2680
	     fromArray:#[ 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2681
			    16r01 16r23
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2682
			    16r45 16r67
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2683
			    16r89 16rab
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2684
			    16rcd 16ref 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2685
			].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2686
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2687
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2688
     i asErrorDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2689
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2690
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2691
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2692
    "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
  2693
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2694
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2695
asFloydSteinbergDitheredDepth8FormOn:aDevice colors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue 
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2696
    "return a floyd-steinberg dithered pseudoForm from the palette picture. 
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2697
     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
  2698
     colors assigned to aDevice, such as the preallocated colors of the
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2699
     Color class. 
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2700
     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
  2701
     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
  2702
     for example to create dithered Depth4Images from Depth8Images."
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2703
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2704
    |pseudoBits f has8BitImage deviceDepth
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2705
     map |
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2706
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2707
    deviceDepth := aDevice depth.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2708
    deviceDepth == 8 ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2709
	has8BitImage := true.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2710
    ] ifFalse:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2711
	has8BitImage := false.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2712
	aDevice supportedImageFormats do:[:fmt |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2713
	    (fmt at:#bitsPerPixel) == 8 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2714
		has8BitImage := true.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2715
	    ]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2716
	]
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2717
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2718
    has8BitImage ifFalse:[^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2719
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2720
    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
  2721
    pseudoBits isNil ifTrue:[^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2722
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2723
    f := Form width:width height:height depth:deviceDepth on:aDevice.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2724
    f isNil ifTrue:[^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2725
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2726
    "/
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2727
    "/ have to create a funny colorMap, where
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2728
    "/ color at:index == color colorId:index
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2729
    "/
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2730
    map := Array new:256.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2731
    fixColors do:[:clr |
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2732
	map at:clr colorId + 1 put:clr
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2733
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2734
    f colorMap:map. 
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2735
    f initGC.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2736
    f bits:pseudoBits.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2737
    aDevice drawBits:pseudoBits bitsPerPixel:8 depth:deviceDepth  
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2738
	       width:width height:height
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2739
		   x:0 y:0
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2740
		into:(f id) x:0 y:0 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2741
	       width:width height:height with:(f gcId).
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2742
    ^ f
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2743
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2744
    "
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2745
     example: 
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2746
	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
  2747
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2748
     |img8 reducedImg8 img4 map form|
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2749
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2750
     map := #( 
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2751
		  (0     0   0)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2752
		  (0     0 100)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2753
		  (0    50   0)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2754
		  (0    50 100)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2755
		  (0   100   0)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2756
		  (0   100 100)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2757
		  (100   0   0)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2758
		  (100   0 100)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2759
		  (100  50   0)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2760
		  (100  50 100)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2761
		  (100 100   0)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2762
		  (100 100 100)) collect:[:rgb | (Color red:(rgb at:1)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2763
						      green:(rgb at:2)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2764
						       blue:(rgb at:3)) on:Display].
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2765
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2766
     img8 := Image fromFile:'bitmaps/bf.im8'.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2767
     form := img8 paletteImageAsDitheredPseudoFormOn:Display 
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2768
		      colors:map 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2769
			nRed:2
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2770
		      nGreen:3
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2771
		       nBlue:2.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2772
     img8 := Depth8Image fromForm:form.    'dithered version of original image'.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2773
     img4 := Depth4Image fromImage:img8.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2774
    "
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2775
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2776
    "Modified: 14.6.1996 / 16:52:34 / cg"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2777
!
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  2778
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2779
asFloydSteinbergDitheredGrayFormOn:aDevice
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2780
    "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
  2781
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  2782
    |depth bits|
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2783
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2784
    depth := aDevice depth.
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  2785
    (depth == 1
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  2786
    or:[aDevice hasGrayscales not]) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2787
	"/ for monochrome, there is specialized
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2788
	"/ monochrome dither code available
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2789
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2790
	bits := self floydSteinbergDitheredMonochromeBits.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2791
    ] ifFalse:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2792
	bits := self floydSteinbergDitheredBitsDepth:depth.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2793
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2794
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  2795
    ^ 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
  2796
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2797
    "
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  2798
     |i|
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2799
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  2800
     i := Image fromFile:'bitmaps/gifImages/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2801
     (i asFloydSteinbergDitheredGrayFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2802
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2803
841
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  2804
    "
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  2805
     |i|
841
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  2806
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  2807
     i := Image fromFile:'bitmaps/granite.tiff'.
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  2808
     (i asFloydSteinbergDitheredGrayFormOn:Display) inspect
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  2809
    "
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  2810
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2811
    "Created: 10.6.1996 / 14:11:39 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  2812
    "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
  2813
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2814
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2815
asFloydSteinbergDitheredGrayImageDepth:depth
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2816
    "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
  2817
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2818
    |ditheredBits|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2819
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  2820
    (depth == 1) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2821
	^ self asFloydSteinbergDitheredMonochromeImage
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2822
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2823
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2824
    ditheredBits := self floydSteinbergDitheredBitsDepth:depth.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2825
    ^ (self class implementorForDepth:depth)
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2826
	width:width height:height fromArray:ditheredBits
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2827
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2828
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2829
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2830
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  2831
     i := Image fromFile:'bitmaps/gifImages/garfield.gif'.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2832
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2833
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2834
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2835
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2836
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2837
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2838
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2839
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2840
829
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2841
     i := Depth24Image width:4 height:1
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2842
	  fromArray:#[ 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2843
	    16rFF 16r00 16r00   16rFF 16r00 16r00  16rFF 16r00 16r00  16rFF 16r00 16r00
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2844
	    16rFF 16r00 16r00   16rFF 16r00 16r00  16rFF 16r00 16r00  16rFF 16r00 16r00
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2845
	    16rFF 16r00 16r00   16rFF 16r00 16r00  16rFF 16r00 16r00  16rFF 16r00 16r00
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2846
	    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
  2847
     i := i magnifiedBy:4@1.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2848
     i inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2849
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2850
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2851
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2852
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2853
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2854
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2855
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2856
     |i|
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2857
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2858
     i := Depth24Image width:4 height:6
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2859
	  fromArray:#[ 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2860
	    16r00 16r00 16r00   16r00 16r00 16r80  16r00 16r00 16rff  16r00 16r80 16r00
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2861
	    16r00 16r80 16r80   16r00 16rFF 16r00  16r00 16rFF 16r80  16r00 16rFF 16rFF
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2862
	    16r80 16r00 16r00   16r80 16r00 16r80  16r80 16r00 16rff  16r80 16r80 16r00
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2863
	    16r80 16r80 16r80   16r80 16rFF 16r00  16r80 16rFF 16r80  16r80 16rFF 16rFF
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2864
	    16rFF 16r00 16r00   16rFF 16r00 16r80  16rFF 16r00 16rff  16rFF 16r80 16r00
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2865
	    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
  2866
     i := i magnifiedBy:30.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2867
     i inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2868
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2869
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2870
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2871
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2872
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2873
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2874
     |i|
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2875
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2876
     i := Image fromFile:'granite.tiff'.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2877
     i inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2878
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2879
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2880
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2881
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2882
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2883
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2884
     |i|
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2885
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  2886
     i := Image fromFile:'bitmaps/gifImages/claus.gif'.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2887
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2888
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2889
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2890
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2891
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2892
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2893
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2894
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2895
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2896
     i := Depth4Image
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2897
	     width:4 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2898
	     height:4
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2899
	     fromArray:#[ 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2900
			    16r01 16r23
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2901
			    16r45 16r67
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2902
			    16r89 16rab
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2903
			    16rcd 16ref 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2904
			].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2905
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2906
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2907
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2908
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2909
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2910
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2911
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2912
    "Created: 10.6.1996 / 12:33:47 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  2913
    "Modified: 17.4.1997 / 01:13:55 / cg"
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2914
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2915
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2916
asFloydSteinbergDitheredMonochromeFormOn:aDevice
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2917
    "return a dithered moncohrome form from the receiver image."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2918
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  2919
    |monoBits|
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  2920
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  2921
    monoBits := self floydSteinbergDitheredMonochromeBits.
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  2922
    ^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2923
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2924
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2925
     |i f|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2926
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  2927
     i := Image fromFile:'bitmaps/gifImages/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2928
     (i asFloydSteinbergDitheredMonochromeFormOn:Display) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2929
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2930
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  2931
    "
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  2932
     |i f|
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  2933
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  2934
     i := Depth2Image width:8 height:8
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2935
	  fromArray:#[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2936
			4r0000 4r0000
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2937
			4r0000 4r0000
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2938
			4r1111 4r1111
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2939
			4r1111 4r1111
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2940
			4r2222 4r2222
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2941
			4r2222 4r2222
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2942
			4r3333 4r3333
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2943
			4r3333 4r3333
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2944
		     ].
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  2945
     (i asFloydSteinbergDitheredMonochromeFormOn:Display) inspect.
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  2946
    "
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  2947
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2948
    "Created: 10.6.1996 / 14:11:39 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  2949
    "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
  2950
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2951
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2952
asFloydSteinbergDitheredMonochromeImage
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2953
    "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
  2954
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2955
    |monoBits|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2956
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2957
    monoBits := self floydSteinbergDitheredMonochromeBits.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2958
    ^ 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
  2959
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2960
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2961
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2962
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2963
     i := Image fromFile:'garfield.gif'.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2964
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2965
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2966
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2967
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2968
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2969
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2970
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2971
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2972
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  2973
     i := Image fromFile:'bitmaps/gifImages/claus.gif'.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2974
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2975
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2976
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2977
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2978
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2979
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2980
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2981
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2982
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2983
     i := Depth4Image
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2984
	     width:4 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2985
	     height:4
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2986
	     fromArray:#[ 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2987
			    16r01 16r23
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2988
			    16r45 16r67
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2989
			    16r89 16rab
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2990
			    16rcd 16ref 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  2991
			].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2992
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2993
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2994
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2995
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2996
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2997
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2998
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2999
    "Created: 10.6.1996 / 12:33:47 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  3000
    "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
  3001
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3002
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3003
asFloydSteinbergDitheredPseudoFormUsing:colors on:aDevice
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3004
    "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
  3005
     using colors in colors for dithering."
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3006
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  3007
    |pseudoBits pseudoBits8 f has8BitImage deviceDepth
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  3008
     map d |
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3009
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3010
    deviceDepth := aDevice depth.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3011
    deviceDepth == 8 ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3012
	has8BitImage := true.
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3013
    ] ifFalse:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3014
	has8BitImage := false.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3015
	aDevice supportedImageFormats do:[:fmt |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3016
	    (fmt at:#bitsPerPixel) == 8 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3017
		has8BitImage := true.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3018
	    ]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3019
	]
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3020
    ].
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  3021
    has8BitImage ifFalse:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3022
	deviceDepth == 4 ifFalse:[^ nil].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3023
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3024
	pseudoBits8 := self nfloydSteinbergDitheredDepth8BitsColors:colors.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3025
	pseudoBits8 isNil ifTrue:[^ nil].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3026
	"/ convert to devices depth
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3027
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3028
	pseudoBits := ByteArray new:(width*4+7//8 * height).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3029
	pseudoBits8 compressPixels:4 width:width height:height into:pseudoBits mapping:nil.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3030
	d := 4.
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  3031
    ] ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3032
	pseudoBits := self nfloydSteinbergDitheredDepth8BitsColors:colors.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3033
	pseudoBits isNil ifTrue:[^ nil].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3034
	d := 8.
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  3035
    ].
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3036
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3037
    f := Form width:width height:height depth:deviceDepth on:aDevice.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3038
    f isNil ifTrue:[^ nil].
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3039
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3040
    "/
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3041
    "/ have to create a funny colorMap, where
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3042
    "/ color at:index == color colorId:index
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3043
    "/
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3044
    map := Array new:256 withAll:0.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3045
    colors do:[:clr |
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3046
	clr notNil ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3047
	    map at:clr colorId + 1 put:clr
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3048
	]
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3049
    ].
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3050
    f colorMap:map. 
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3051
    f initGC.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3052
    f bits:pseudoBits.
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  3053
    aDevice drawBits:pseudoBits bitsPerPixel:d depth:deviceDepth  
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3054
	       width:width height:height
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3055
		   x:0 y:0
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3056
		into:(f id) x:0 y:0 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3057
	       width:width height:height with:(f gcId).
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3058
    ^ f
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3059
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3060
    "
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3061
     |i|
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3062
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3063
     i := Image fromFile:'bitmaps/garfield.gif'.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3064
     (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
  3065
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3066
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3067
     |i|
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3068
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3069
     i := Image fromFile:'bitmaps/claus.gif'.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3070
     (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
  3071
    "
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3072
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3073
    "Created: 17.6.1996 / 12:13:35 / cg"
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  3074
    "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
  3075
!
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3076
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3077
asFormOn:aDevice
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  3078
    "get a device form, with best possible approximation.
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  3079
     remember it in case someone asks again."
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  3080
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  3081
    |form visual|
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  3082
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  3083
    ((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ deviceForm].
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3084
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
  3085
    mask notNil ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3086
	mask := mask on:aDevice
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
  3087
    ].
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
  3088
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  3089
    (aDevice depth == 1
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  3090
    or:[aDevice hasGrayscales not]) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3091
	^ self asMonochromeFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3092
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3093
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  3094
    ((visual := aDevice visualType) == #StaticGray) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3095
	^ self asGrayFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3096
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3097
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  3098
    (visual == #PseudoColor
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  3099
     or:[visual == #StaticColor]) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3100
	form := self asPseudoFormQuickOn:aDevice.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3101
	form notNil ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3102
	    ^ form
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3103
	].
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3104
    ].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3105
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3106
    (photometric == #palette) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3107
	form := self paletteImageAsFormOn:aDevice
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  3108
    ] ifFalse:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3109
	(photometric == #rgb) ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3110
	    form := self rgbImageAsFormOn:aDevice
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3111
	] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3112
	    form := self greyImageAsFormOn:aDevice
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3113
	]
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3114
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
  3115
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  3116
    (device isNil or:[aDevice == device]) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3117
	"remember this form in the receiver ..."
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3118
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3119
	form notNil ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3120
	    deviceForm := form.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3121
	    device isNil ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3122
		device := aDevice.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3123
		Lobby register:self
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3124
	    ] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3125
		Lobby registerChange:self
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3126
	    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3127
	    "
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3128
	     can save space, by not keeping the images data-bits
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3129
	     twice (here and in the device form)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3130
	    "
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3131
	    form forgetBits
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3132
	]
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3133
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
  3134
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  3135
    ^ form
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3136
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  3137
    "Modified: 10.7.1996 / 21:55:44 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3138
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3139
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3140
asGrayFormOn:aDevice
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3141
    "get a gray device form"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3142
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3143
    ^ self asGrayFormOn:aDevice dither:DitherAlgorithm.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3144
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3145
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3146
     |i|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3147
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3148
     i := Image fromFile:'bitmaps/claus.gif'.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3149
     (i asGrayFormOn:Display) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3150
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3151
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3152
    "Modified: 10.6.1996 / 17:39:30 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3153
    "Created: 10.6.1996 / 18:44:42 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3154
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3155
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3156
asGrayFormOn:aDevice dither:aDitherAlgorithm
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3157
    "get a greyscale device form, using aDitherAlgorithm."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3158
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  3159
    |depth|
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3160
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3161
    depth := aDevice depth.
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  3162
    (depth == 1
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  3163
    or:[aDevice hasGrayscales not]) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3164
	^ self asMonochromeFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3165
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3166
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3167
    (aDitherAlgorithm isNil
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3168
    or:[aDitherAlgorithm == #threshold]) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3169
	^ self asThresholdGrayFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3170
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3171
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3172
    (aDitherAlgorithm == #pattern
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3173
    or:[aDitherAlgorithm == #ordered]) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3174
	^ self asOrderedDitheredGrayFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3175
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3176
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3177
    ^ self asFloydSteinbergDitheredGrayFormOn:aDevice.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3178
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3179
    "Created: 10.6.1996 / 18:42:01 / cg"
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  3180
    "Modified: 14.6.1996 / 15:17:28 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3181
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3182
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3183
asGrayImageDepth:depth
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3184
    "get a gray image from the receiver"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3185
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3186
    ^ self asGrayImageDepth:depth dither:DitherAlgorithm.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3187
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3188
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3189
     |i|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3190
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3191
     i := Image fromFile:'bitmaps/claus.gif'.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3192
     (i asGrayFormOn:Display) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3193
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3194
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3195
    "Modified: 10.6.1996 / 17:39:30 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3196
    "Created: 10.6.1996 / 19:07:08 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3197
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3198
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3199
asGrayImageDepth:depth dither:aDitherAlgorithm
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3200
    "get a greyscale image, using aDitherAlgorithm."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3201
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3202
    (aDitherAlgorithm isNil
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3203
    or:[aDitherAlgorithm == #threshold]) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3204
	^ self asThresholdGrayImageDepth:depth
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3205
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3206
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3207
    (aDitherAlgorithm == #pattern
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3208
    or:[aDitherAlgorithm == #ordered]) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3209
	^ self asOrderedDitheredGrayImageDepth:depth
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3210
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3211
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3212
    ^ self asFloydSteinbergDitheredGrayImageDepth:depth
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3213
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3214
    "Created: 10.6.1996 / 19:08:21 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3215
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  3216
48194c26a46c Initial revision
claus
parents:
diff changeset
  3217
asMonochromeFormOn:aDevice
48194c26a46c Initial revision
claus
parents:
diff changeset
  3218
    "get a monochrome device form"
48194c26a46c Initial revision
claus
parents:
diff changeset
  3219
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  3220
    |form|
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  3221
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  3222
    ((aDevice == device) and:[monoDeviceForm notNil]) ifTrue:[^ monoDeviceForm].
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  3223
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3224
    form := self asMonochromeFormOn:aDevice dither:DitherAlgorithm.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3225
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  3226
    (device isNil or:[aDevice == device]) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3227
	"remember this form in the receiver ..."
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3228
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3229
	form notNil ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3230
	    monoDeviceForm := form.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3231
	    device isNil ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3232
		device := aDevice.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3233
		Lobby register:self
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3234
	    ] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3235
		Lobby registerChange:self
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3236
	    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3237
	    "
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3238
	     can save space, by not keeping the images data-bits
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3239
	     twice (here and in the device form)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3240
	    "
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3241
	    form forgetBits
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3242
	]
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3243
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
  3244
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  3245
    ^ form
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3246
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3247
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3248
     |i|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3249
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3250
     i := Image fromFile:'bitmaps/claus.gif'.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3251
     (i asMonochromeFormOn:Display) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3252
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3253
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3254
    "Modified: 10.6.1996 / 17:39:30 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3255
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3256
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3257
asMonochromeFormOn:aDevice dither:aDitherAlgorithm
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3258
    "get a monochrome device form, using aDitherAlgorithm."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3259
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  3260
    |monoBits|
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3261
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3262
    (aDitherAlgorithm isNil
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3263
    or:[aDitherAlgorithm == #threshold]) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3264
	^ self asThresholdMonochromeFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3265
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3266
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3267
    aDitherAlgorithm == #burkes ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3268
	monoBits := self burkesDitheredMonochromeBits.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3269
    ] ifFalse:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3270
	aDitherAlgorithm == #stevensonArce ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3271
	    monoBits := self stevensonArceDitheredMonochromeBits.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3272
	] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3273
	    (aDitherAlgorithm == #pattern
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3274
	    or:[aDitherAlgorithm == #ordered]) ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3275
		^ self asOrderedDitheredGrayFormOn:aDevice.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3276
	    ] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3277
		^ self asFloydSteinbergDitheredMonochromeFormOn:aDevice.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3278
	    ]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3279
	]
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3280
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3281
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3282
    "/
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3283
    "/ make its pixel interpretation correct for the device
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3284
    "/
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3285
    ^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3286
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3287
    "Modified: 10.6.1996 / 20:18:05 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  3288
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  3289
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3290
asNearestPaintDepth8FormOn:aDevice colors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue 
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3291
    "return a nearest paint pseudoForm from the palette picture. 
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3292
     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
  3293
     colors assigned to aDevice, such as the preallocated colors of the
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3294
     Color class. 
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3295
     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
  3296
     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
  3297
     for example to create dithered Depth4Images from Depth8Images."
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3298
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3299
    |pseudoBits f has8BitImage deviceDepth
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3300
     map |
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3301
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3302
    deviceDepth := aDevice depth.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3303
    deviceDepth == 8 ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3304
	has8BitImage := true.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3305
    ] ifFalse:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3306
	has8BitImage := false.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3307
	aDevice supportedImageFormats do:[:fmt |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3308
	    (fmt at:#bitsPerPixel) == 8 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3309
		has8BitImage := true.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3310
	    ]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3311
	]
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3312
    ].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3313
    has8BitImage ifFalse:[^ nil].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3314
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3315
    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
  3316
    pseudoBits isNil ifTrue:[^ nil].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3317
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3318
    f := Form width:width height:height depth:deviceDepth on:aDevice.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3319
    f isNil ifTrue:[^ nil].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3320
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3321
    "/
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3322
    "/ have to create a funny colorMap, where
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3323
    "/ color at:index == color colorId:index
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3324
    "/
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3325
    map := Array new:256.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3326
    fixColors do:[:clr |
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3327
	map at:clr colorId + 1 put:clr
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3328
    ].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3329
    f colorMap:map. 
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3330
    f initGC.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3331
    f bits:pseudoBits.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3332
    aDevice drawBits:pseudoBits bitsPerPixel:8 depth:deviceDepth  
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3333
	       width:width height:height
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3334
		   x:0 y:0
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3335
		into:(f id) x:0 y:0 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3336
	       width:width height:height with:(f gcId).
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3337
    ^ f
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3338
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3339
    "
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3340
     example: 
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3341
	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
  3342
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3343
     |img8 reducedImg8 img4 map form|
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3344
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3345
     map := #( 
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3346
		  (0     0   0)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3347
		  (0     0 100)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3348
		  (0    50   0)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3349
		  (0    50 100)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3350
		  (0   100   0)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3351
		  (0   100 100)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3352
		  (100   0   0)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3353
		  (100   0 100)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3354
		  (100  50   0)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3355
		  (100  50 100)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3356
		  (100 100   0)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3357
		  (100 100 100)) collect:[:rgb | (Color red:(rgb at:1)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3358
						      green:(rgb at:2)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3359
						       blue:(rgb at:3)) on:Display].
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3360
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3361
     img8 := Image fromFile:'bitmaps/claus.gif'.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3362
     form := img8 asNearestPaintDepth8FormOn:Display 
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3363
		      colors:map 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3364
			nRed:2
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3365
		      nGreen:3
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3366
		       nBlue:2.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3367
     img8 := Depth8Image fromForm:form.    'dithered version of original image'.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3368
     img4 := Depth4Image fromImage:img8.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3369
    "
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3370
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3371
    "Created: 17.6.1996 / 18:47:46 / cg"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3372
    "Modified: 17.6.1996 / 18:52:47 / cg"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3373
!
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  3374
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  3375
asOrderedDitheredGrayFormOn:aDevice
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  3376
    "return a dithered depth-x grey form from the receiver image.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  3377
     Uses an 8x8 dithermatrix."
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  3378
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  3379
    |depth bits|
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  3380
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  3381
    depth := aDevice depth.
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  3382
    (depth == 1 
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  3383
    or:[aDevice hasGrayscales not]) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3384
	"/ for monochrome, there is highly specialized
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3385
	"/ monochrome dither code available
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3386
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3387
	^ self asOrderedDitheredMonochromeFormOn:aDevice
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  3388
    ].
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  3389
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3390
    bits := self
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3391
		orderedDitheredBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3392
		ditherWidth:8
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3393
		depth:depth.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3394
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3395
    ^ self makeDeviceGrayPixmapOn:aDevice depth:depth fromArray:bits
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3396
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3397
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3398
     |i|
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  3399
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  3400
     i := Image fromFile:'bitmaps/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3401
     (i asOrderedDitheredGrayFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3402
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3403
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3404
    "Modified: 10.6.1996 / 20:10:07 / cg"
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  3405
!
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  3406
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3407
asOrderedDitheredGrayImageDepth:depth
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3408
    "return a dithered depth-x grey image from the receiver image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3409
     Uses an 8x8 dithermatrix."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3410
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3411
    |dither|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3412
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3413
    dither := self class orderedDitherMatrixOfSize:8.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3414
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  3415
    (depth == 1) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3416
	"/ for monochrome, there is highly specialized
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3417
	"/ monochrome dither code available
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3418
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3419
	^ Depth1Image
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3420
	    width:width
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3421
	    height:height
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3422
	    fromArray:(
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3423
		self
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3424
		    orderedDitheredMonochromeBitsWithDitherMatrix:dither
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3425
		    ditherWidth:8)
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3426
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3427
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3428
    ^ (self class implementorForDepth:depth)
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3429
	width:width
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3430
	height:height
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3431
	fromArray:(
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3432
	    self
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3433
		orderedDitheredBitsWithDitherMatrix:dither
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3434
		ditherWidth:8
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3435
		depth:depth)
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3436
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3437
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3438
     |i i1 i2 i4 i8|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3439
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3440
     i := Image fromFile:'bitmaps/claus.gif'.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3441
     i1 := i asOrderedDitheredGrayImageDepth:1.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3442
     i1 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3443
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3444
     i2 := i asOrderedDitheredGrayImageDepth:2.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3445
     i2 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3446
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3447
     i4 := i asOrderedDitheredGrayImageDepth:4.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3448
     i4 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3449
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3450
     i8 := i asOrderedDitheredGrayImageDepth:8.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3451
     i8 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3452
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3453
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3454
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3455
     |i i1 i2 i4 i8|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3456
     i := Image fromFile:'bitmaps/garfield.gif'.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3457
     i1 := i asOrderedDitheredGrayImageDepth:1.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3458
     i1 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3459
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3460
     i2 := i asOrderedDitheredGrayImageDepth:2.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3461
     i2 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3462
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3463
     i4 := i asOrderedDitheredGrayImageDepth:4.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3464
     i4 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3465
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3466
     i8 := i asOrderedDitheredGrayImageDepth:8.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3467
     i8 inspect.
800
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3468
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3469
     i2 := i8 asOrderedDitheredGrayImageDepth:2.
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3470
     i2 inspect.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3471
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3472
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3473
    "Created: 7.6.1996 / 18:03:54 / cg"
800
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3474
    "Modified: 7.6.1996 / 19:41:59 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3475
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3476
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3477
asOrderedDitheredMonochromeFormOn:aDevice
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3478
    "return a dithered monochrome form from the grey image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3479
     Uses a 4x4 dithermatrix."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3480
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3481
    "/ 4x4 seems a good comprimize between:
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3482
    "/    number of grey levels (8x8 is better)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3483
    "/    artifacts             (4x4 is better)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3484
    "/
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3485
    "/ could look at the image and decide upon the number of
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3486
    "/ distinct colors present. Use 8x8 for high-number,
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3487
    "/ 4x4 for small number of colors ...
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3488
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3489
    ^ self 
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3490
	asOrderedDitheredMonochromeFormOn:aDevice 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3491
	ditherMatrix:(self class orderedDitherMatrixOfSize:4)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3492
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3493
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3494
"/    ^ self 
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3495
"/        asOrderedDitheredMonochromeFormOn:aDevice 
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3496
"/        ditherMatrix:(self class orderedDitherMatrixOfSize:8)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3497
"/        ditherWidth:8
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3498
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3499
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3500
     |i f|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3501
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  3502
     i := Image fromFile:'bitmaps/gifImages/claus.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3503
     f := i asOrderedDitheredMonochromeFormOn:Display.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3504
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3505
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3506
     |i f|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3507
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  3508
     i := (Image fromFile:'bitmaps/winBitmaps/a11.ico') magnifiedBy:10.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3509
     f := i asOrderedDitheredMonochromeFormOn:Display.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3510
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3511
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3512
     |i f|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3513
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  3514
     i := Image fromFile:'bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3515
     f := i asOrderedDitheredMonochromeFormOn:Display.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3516
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3517
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3518
     |i f|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3519
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3520
     i := (Image fromFile:'bitmaps/PasteButton.tiff') magnifiedBy:10.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3521
     f := i asOrderedDitheredMonochromeFormOn:Display.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3522
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3523
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3524
     |i f|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3525
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3526
     i := (Image fromFile:'bitmaps/blue-ball.gif') magnifiedBy:1.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3527
     f := i asOrderedDitheredMonochromeFormOn:Display.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3528
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3529
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3530
    "Created: 7.6.1996 / 14:52:32 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  3531
    "Modified: 17.4.1997 / 01:10:10 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3532
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3533
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3534
asOrderedDitheredMonochromeFormOn:aDevice ditherMatrix:ditherMatrix ditherWidth:dW
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3535
    "return a dithered monochrome form from the image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3536
     Uses the passed ditherMatrix and ditherWidth."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3537
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  3538
    |monoBits|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3539
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3540
    monoBits := self orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW.
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3541
    ^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3542
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3543
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3544
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3545
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3546
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  3547
     i := Image fromFile:'bitmaps/gifImages/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3548
     (i asOrderedDitheredMonochromeFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3549
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3550
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3551
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3552
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3553
     i := Image fromFile:'bitmaps/granite.tiff'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3554
     (i asOrderedDitheredMonochromeFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3555
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3556
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3557
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3558
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3559
     i := (Image fromFile:'bitmaps/PasteButton.tiff') magnifiedBy:10.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3560
     (i asOrderedDitheredMonochromeFormOn:Display) inspect
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3561
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3562
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3563
    "Created: 7.6.1996 / 14:51:42 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  3564
    "Modified: 17.4.1997 / 01:08:24 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3565
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3566
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3567
asOrderedDitheredMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3568
    "return a dithered monochrome image from the receiver image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3569
     Uses a 4x4 dithermatrix."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3570
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3571
    "/ 4x4 seems a good comprimize between:
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3572
    "/    number of grey levels (8x8 is better)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3573
    "/    artifacts             (4x4 is better)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3574
    "/
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3575
    "/ could look at the image and decide upon the number of
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3576
    "/ distinct colors present. Use 8x8 for high-number,
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3577
    "/ 4x4 for small number of colors ...
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3578
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3579
    ^ self 
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3580
	asOrderedDitheredMonochromeImageWithDitherMatrix:(self class orderedDitherMatrixOfSize:4)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3581
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3582
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3583
"/    ^ self 
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3584
"/        asOrderedDitheredMonochromeImageWithDitherMatrix:(self class orderedDitherMatrixOfSize:8)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3585
"/        ditherWidth:8
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3586
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3587
    "
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3588
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3589
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3590
     i := Image fromFile:'bitmaps/claus.gif'.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3591
     i asOrderedDitheredMonochromeImage inspect
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3592
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3593
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3594
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3595
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3596
     i := (Image fromFile:'/cdrom/icons/a/a11.ico') magnifiedBy:10.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3597
     i asOrderedDitheredMonochromeImage inspect
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3598
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3599
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3600
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3601
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3602
     i := Image fromFile:'bitmaps/garfield.gif'.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3603
     i asOrderedDitheredMonochromeImage inspect
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3604
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3605
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3606
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3607
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3608
     i := (Image fromFile:'bitmaps/PasteButton.tiff') magnifiedBy:10.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3609
     i asOrderedDitheredMonochromeImage inspect
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3610
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3611
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3612
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3613
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3614
     i := (Image fromFile:'bitmaps/blue-ball.gif') magnifiedBy:1.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3615
     i asOrderedDitheredMonochromeImage inspect
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3616
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3617
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3618
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3619
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3620
     i := Image fromFile:'bitmaps/granite.tiff'.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3621
     i asOrderedDitheredMonochromeImage inspect
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3622
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3623
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3624
    "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
  3625
    "Modified: 10.6.1996 / 11:15:09 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3626
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3627
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3628
asOrderedDitheredMonochromeImageWithDitherMatrix:ditherMatrix ditherWidth:dW
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3629
    "return a dithered monochrome image from the receiver image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3630
     Uses the passed ditherMatrix and ditherWidth."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3631
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3632
    |monoBits|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3633
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3634
    monoBits := self orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3635
    ^ (Depth1Image width:width height:height fromArray:monoBits) photometric:#blackIs0
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3636
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3637
    "order-4 dither:
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3638
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3639
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3640
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3641
     i := Image fromFile:'garfield.gif'.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3642
     i
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3643
	asOrderedDitheredMonochromeImageWithDitherMatrix:(Image orderedDitherMatrixOfSize:4)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3644
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3645
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3646
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3647
    "order-6 dither:
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3648
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3649
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3650
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3651
     i := Image fromFile:'garfield.gif'.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3652
     i
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3653
	asOrderedDitheredMonochromeImageWithDitherMatrix:(Image orderedDitherMatrixOfSize:8)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3654
	ditherWidth:8
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3655
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3656
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3657
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3658
    "thresholding at:0.5 (all above 0.5 becomes white):
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3659
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3660
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3661
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3662
     i := Image fromFile:'garfield.gif'.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3663
     i
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3664
	asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:8)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3665
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3666
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3667
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3668
    "thresholding at: 0.25 (all above 0.25 becomes white):
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3669
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3670
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3671
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3672
     i := Image fromFile:'garfield.gif'.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3673
     i
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3674
	asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:3)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3675
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3676
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3677
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3678
    "thresholding at: 0.75 (all above 0.75 becomes white):
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3679
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3680
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3681
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3682
     i := Image fromFile:'garfield.gif'.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3683
     i
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3684
	asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:11)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3685
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3686
    "
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
    "Modified: 7.6.1996 / 17:23:47 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3689
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3690
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3691
asPseudoFormQuickOn:aDevice
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3692
    "return a pseudo-deviceForm from the image.
878
b99add8dc742 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 874
diff changeset
  3693
     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
  3694
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  3695
    |f d dDev temp temp8 bits clr cMap idMap 
878
b99add8dc742 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 874
diff changeset
  3696
     nClr "{ Class: SmallInteger }"
b99add8dc742 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 874
diff changeset
  3697
     usedColors |
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3698
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3699
    d := self depth.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3700
    (d == 1
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3701
    or:[d == 2
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3702
    or:[d == 4
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3703
    or:[d == 8]]]) ifFalse:[^ nil].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3704
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3705
    "/
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3706
    "/ see if all of the images colors are representable
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3707
    "/ on the device
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3708
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3709
    bits := self bitsPerPixel.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3710
    nClr := (1 bitShift:bits).
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3711
    cMap := Array new:nClr.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3712
    idMap := ByteArray new:nClr.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3713
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3714
    photometric == #palette ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3715
	nClr := nClr min:(colorMap size)
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3716
    ].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3717
878
b99add8dc742 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 874
diff changeset
  3718
    d == 8 ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3719
	usedColors := bytes usedValues.    "gets us an array filled with used values"
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3720
	1 to:nClr do:[:pixel |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3721
	    (usedColors includes:(pixel - 1)) ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3722
		clr := Color black
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3723
	    ] ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3724
		clr := self colorFromValue:pixel-1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3725
		clr := clr exactOn:aDevice.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3726
		clr isNil ifTrue:[^ nil].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3727
	    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3728
	    cMap at:(pixel) put:clr.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3729
	    idMap at:(pixel) put:(clr colorId).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3730
	].
878
b99add8dc742 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 874
diff changeset
  3731
    ] ifFalse:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3732
	1 to:nClr do:[:pixel |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3733
	    clr := self colorFromValue:pixel-1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3734
	    clr := clr exactOn:aDevice.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3735
	    clr isNil ifTrue:[^ nil].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3736
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3737
	    cMap at:(pixel) put:clr.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3738
	    idMap at:(pixel) put:(clr colorId).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3739
	].
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3740
    ].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3741
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3742
    "/ got all colors; good - simply change depth & translate pixels
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3743
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3744
    dDev := aDevice depth.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3745
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3746
    (d == 8 and:[dDev == 8]) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3747
	"/ only translate
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3748
	temp := ByteArray uninitializedNew:(width * height).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3749
	bytes expandPixels:8         "xlate only"
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3750
		    width:width 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3751
		   height:height
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3752
		     into:temp
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3753
		  mapping:idMap.
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3754
    ] ifFalse:[
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3755
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3756
	"/ stupid: expandPixels can only handle any-to-8
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3757
	"/ compressPixels can only handle 8-to-any
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3758
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3759
	d ~~ 8 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3760
	    temp8 := ByteArray uninitializedNew:(width * height).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3761
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3762
	    bytes expandPixels:d      
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3763
			 width:width 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3764
			height:height
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3765
			  into:temp8
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3766
		       mapping:idMap.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3767
	    idMap := nil.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3768
	] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3769
	    temp8 := bytes.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3770
	].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3771
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3772
	dDev ~~ 8 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3773
	    temp := ByteArray uninitializedNew:((width * dDev + 7) // 8 * height).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3774
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3775
	    temp8 compressPixels:dDev      
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3776
			 width:width 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3777
			height:height
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3778
			  into:temp
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3779
		       mapping:idMap.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3780
	] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3781
	    temp := temp8
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3782
	].
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3783
    ].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3784
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3785
    f := Form width:width height:height depth:dDev on:aDevice.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3786
    f isNil ifTrue:[^ nil].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3787
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3788
    f colorMap:cMap. 
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3789
    f initGC.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3790
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3791
    aDevice 
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3792
	drawBits:temp 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3793
	depth:dDev 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3794
	width:width 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3795
	height:height
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3796
	x:0 y:0
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3797
	into:(f id) x:0 y:0 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3798
	width:width 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3799
	height:height 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3800
	with:(f gcId).
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3801
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3802
    ^ f
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3803
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3804
    "
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3805
     (
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3806
	(((Depth4Image
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3807
	     width:4 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3808
	     height:4
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3809
	     fromArray:#[ 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3810
			    16r01 16r23
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3811
			    16r45 16r67
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3812
			    16r89 16rab
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3813
			    16rcd 16ref 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3814
			]))
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3815
	       magnifiedBy:30
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3816
	 )
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3817
	  asPseudoFormQuickOn:Display
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3818
      ) inspect
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3819
     "
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3820
878
b99add8dc742 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 874
diff changeset
  3821
    "Modified: 17.6.1996 / 17:31:49 / cg"
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3822
!
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3823
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3824
asStevensonArceDitheredMonochromeImage
837
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  3825
    "return a stevenson-arce dithered monochrome image from the receiver image.
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  3826
     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
  3827
     a floyd-steinberg dithered image.
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  3828
     Notice, that floyd-steinberg dithering is faster; both because less
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  3829
     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
  3830
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3831
    |monoBits|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3832
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3833
    monoBits := self stevensonArceDitheredMonochromeBits.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3834
    ^ (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
  3835
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3836
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3837
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3838
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3839
     i := Image fromFile:'garfield.gif'.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3840
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3841
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3842
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3843
     i asStevensonArceDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3844
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3845
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3846
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3847
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3848
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3849
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3850
     i := Image fromFile:'claus.gif'.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3851
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3852
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3853
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3854
     i asStevensonArceDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3855
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3856
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3857
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3858
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3859
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3860
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3861
     i := Depth4Image
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3862
	     width:4 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3863
	     height:4
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3864
	     fromArray:#[ 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3865
			    16r01 16r23
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3866
			    16r45 16r67
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3867
			    16r89 16rab
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3868
			    16rcd 16ref 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3869
			].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3870
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3871
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3872
     i asStevensonArceDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3873
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3874
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3875
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3876
    "Created: 10.6.1996 / 12:38:29 / cg"
837
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  3877
    "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
  3878
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3879
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3880
asThresholdGrayFormOn:aDevice
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3881
    "return a thresholded grey form from the receiver image."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3882
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3883
    |depth|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3884
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3885
    (depth := aDevice depth) == 1 ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3886
	^ self asThresholdMonochromeFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3887
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3888
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3889
    ^ self 
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3890
	makeDeviceGrayPixmapOn:aDevice 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3891
	depth:depth 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3892
	fromArray:(self
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3893
			orderedDitheredBitsWithDitherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3894
			ditherWidth:4
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3895
			depth:depth)
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3896
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3897
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3898
     |i|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3899
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3900
     i := Image fromFile:'bitmaps/claus.gif'.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3901
     (i asThresholdGrayFormOn:Display) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3902
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3903
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3904
    "Created: 10.6.1996 / 18:38:31 / cg"
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3905
    "Modified: 10.6.1996 / 20:10:26 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3906
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3907
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3908
asThresholdGrayImageDepth:depth
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3909
    "return a thresholded depth-x grey image from the receiver image."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3910
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  3911
    (depth == 1) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3912
	"/ for monochrome, there is highly specialized
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3913
	"/ monochrome dither code available
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3914
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3915
	^ Depth1Image
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3916
	    width:width
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3917
	    height:height
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3918
	    fromArray:(
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3919
		self
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3920
		    orderedDitheredMonochromeBitsWithDitherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3921
		    ditherWidth:4)
800
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3922
    ].
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3923
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3924
    ^ (self class implementorForDepth:depth)
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3925
	width:width
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3926
	height:height
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3927
	fromArray:(
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3928
	    self
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3929
		orderedDitheredBitsWithDitherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3930
		ditherWidth:4
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3931
		depth:depth)
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3932
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3933
    "
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3934
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3935
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3936
     i := Image fromFile:'bitmaps/claus.gif'.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3937
     (i asThresholdGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3938
     (i asThresholdGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3939
     (i asThresholdGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3940
     (i asThresholdGrayImageDepth:8) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3941
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3942
     (i asOrderedDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3943
     (i asOrderedDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3944
     (i asOrderedDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3945
     (i asOrderedDitheredGrayImageDepth:8) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3946
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3947
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3948
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3949
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3950
     (i asFloydSteinbergDitheredGrayImageDepth:8) inspect.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3951
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3952
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3953
    "Created: 7.6.1996 / 18:13:33 / cg"
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3954
    "Modified: 10.6.1996 / 14:20:56 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3955
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3956
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3957
asThresholdMonochromeFormOn:aDevice
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3958
    "return a threshold monochrome form from the image."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3959
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3960
    ^ self 
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3961
	asOrderedDitheredMonochromeFormOn:aDevice 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3962
	ditherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  3963
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3964
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3965
    "
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3966
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3967
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3968
     i := Image fromFile:'bitmaps/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3969
     i inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3970
     (i asThresholdMonochromeFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3971
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3972
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3973
     |i|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3974
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3975
     i := (Image fromFile:'bitmaps/a11.ico') magnifiedBy:10.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3976
     i inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3977
     (i asThresholdMonochromeFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3978
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3979
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3980
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3981
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3982
     i := Image fromFile:'bitmaps/granite.tiff'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3983
     i inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3984
     (i asThresholdMonochromeFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3985
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3986
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3987
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3988
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3989
     i := (Image fromFile:'bitmaps/PasteButton.tiff') magnifiedBy:10.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3990
     i inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3991
     (i asThresholdMonochromeFormOn:Display) inspect
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3992
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3993
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3994
    "Created: 7.6.1996 / 16:15:17 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3995
    "Modified: 10.6.1996 / 17:44:29 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3996
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3997
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3998
asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3999
    "return a threshold monochrome image from the image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4000
     Threshold means: brightness < 0.5 -> black / otherwise white"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4001
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4002
    ^ self
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4003
	asOrderedDitheredMonochromeImageWithDitherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4004
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4005
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4006
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4007
     |i i2|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4008
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4009
     i := Image fromFile:'bitmaps/claus.gif'.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4010
     i2 := i asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4011
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4012
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4013
     |i i2|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4014
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4015
     i := (Image fromFile:'/cdrom/icons/a/a11.ico') magnifiedBy:10.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4016
     i2 := i asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4017
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4018
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4019
     |i i2|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4020
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4021
     i := Image fromFile:'bitmaps/granite.tiff'.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4022
     i2 := i asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4023
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4024
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4025
     |i i2|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4026
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4027
     i := (Image fromFile:'bitmaps/PasteButton.tiff') magnifiedBy:10.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4028
     i2 := i asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4029
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4030
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4031
    "Created: 7.6.1996 / 16:15:17 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4032
    "Modified: 7.6.1996 / 17:16:10 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4033
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4034
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4035
asThresholdMonochromeImage:thresholdBrighness
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4036
    "return a threshold monochrome image from the image.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4037
     The argument (0..1) gives the threshold value;
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4038
     Threshold means: brightness < threshold -> black / otherwise white"
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4039
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4040
    |value ditherMatrix|
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4041
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4042
    value := thresholdBrighness * 255.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4043
    ditherMatrix := ByteArray new:256 withAll:(value truncated).
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4044
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4045
    ^ self
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4046
	asOrderedDitheredMonochromeImageWithDitherMatrix:ditherMatrix
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4047
	ditherWidth:16
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4048
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4049
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4050
     |i|
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4051
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4052
     i := Image width:4 height:4 depth:4
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4053
		fromArray:#[ 16r01 16r23
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4054
			     16r45 16r67
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4055
			     16r89 16rab
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4056
			     16rcd 16ref ].
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4057
     i := i magnifiedBy:30.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4058
     i inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4059
     (i asThresholdMonochromeImage:0.125) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4060
     (i asThresholdMonochromeImage:0.25) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4061
     (i asThresholdMonochromeImage:0.5) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4062
     (i asThresholdMonochromeImage:0.75) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4063
     (i asThresholdMonochromeImage:1) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4064
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4065
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4066
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4067
     |i|
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4068
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4069
     i := Image fromFile:'bitmaps/claus.gif'.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4070
     i inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4071
     (i asThresholdMonochromeImage:0.125) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4072
     (i asThresholdMonochromeImage:0.25) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4073
     (i asThresholdMonochromeImage:0.5) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4074
     (i asThresholdMonochromeImage:0.625) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4075
     (i asThresholdMonochromeImage:0.75) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4076
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4077
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4078
    "Created: 7.6.1996 / 16:15:17 / cg"
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4079
    "Modified: 8.6.1996 / 14:51:57 / cg"
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4080
!
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4081
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4082
clearMaskedPixels
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4083
    "assuming that I already have a device representation
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4084
     in deviceForm, clear any masked pixels.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4085
     This will allow faster drawing in the future."
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4086
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4087
    maskedPixelsAre0 == true ifTrue:[^ self].   "/ already cleared
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4088
    mask isNil ifTrue:[^ self].         "/ no mask
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4089
    deviceForm isNil ifTrue:[^ self].   "/ no device rep.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4090
    mask depth ~~ 1 ifTrue:[^ self].    "/ not done with alpha masks
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4091
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4092
    deviceForm foreground:Color allColor background:Color noColor.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4093
    deviceForm function:#and.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4094
    deviceForm copyPlaneFrom:(mask asFormOn:device) x:0 y:0 toX:0 y:0 width:width height:height.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4095
    maskedPixelsAre0 := true.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4096
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4097
    "Created: 12.4.1997 / 12:18:05 / cg"
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4098
    "Modified: 12.4.1997 / 12:20:19 / cg"
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4099
!
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4100
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4101
fromForm:aForm
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  4102
    "setup the receiver from a form"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4103
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4104
    |map c0 c1|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4105
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4106
    width := aForm width.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4107
    height := aForm height.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4108
    bitsPerSample := self bitsPerSample.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4109
    samplesPerPixel := self samplesPerPixel.
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  4110
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  4111
    aForm hasBits ifFalse:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4112
	"/ must read the data from the device
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4113
	self from:aForm in:(0@0 extent:aForm extent).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4114
	^ self
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  4115
    ].
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  4116
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  4117
    "/ the form has all data available
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  4118
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  4119
    bytes := aForm bits.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4120
    map := aForm colorMap.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4121
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4122
    aForm depth == 1 ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4123
	map isNil ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4124
	    photometric := #whiteIs0
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4125
	] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4126
	    c0 := map at:1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4127
	    c1 := map at:2.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4128
	    ((c0 = Color white)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4129
	    and:[c1 = Color black]) ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4130
		photometric := #whiteIs0
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4131
	    ] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4132
		((c0 = Color black)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4133
		and:[c1 = Color white]) ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4134
		    photometric := #blackIs0
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4135
		] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4136
		    photometric := #palette.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4137
		    colorMap := Array with:c0 with:c1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4138
		]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4139
	    ]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4140
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4141
    ] ifFalse:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4142
	map notNil ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4143
	    photometric := #palette.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4144
	    colorMap := map copy.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4145
	] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4146
	    "
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4147
	     photometric stays at default
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4148
	     (which is rgb for d24, greyscale for others)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4149
	    "
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4150
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4151
    ].
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  4152
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  4153
    "Modified: 5.7.1996 / 16:24:31 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4154
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4155
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4156
fromImage:anImage
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4157
    "setup the receiver from another image.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4158
     Color precision may be lost, if conversion is from a higher depth
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4159
     image. 
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4160
     WARNING:
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4161
     This implementation is a slow fallback (the loop over the
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4162
     source pixels is very slow). If this method is used heavily, you
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4163
     may want to redefine it in concrete subclasses for common source images."
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4164
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4165
    |map clr rowPixels mappedRowPixels|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4166
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4167
    width := anImage width.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4168
    height := anImage height.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4169
    bitsPerSample := self bitsPerSample.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4170
    samplesPerPixel := self samplesPerPixel.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4171
    self colormapFromImage:anImage.
1374
ab515c0576c6 preserve mask when creating an image from another image.
Claus Gittinger <cg@exept.de>
parents: 1362
diff changeset
  4172
    self mask:anImage mask.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4173
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4174
    self depth = anImage depth ifTrue:[
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4175
        bytes := anImage bits copy.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4176
        ^ self.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4177
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4178
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4179
    bytes := ByteArray uninitializedNew:(self bytesPerRow * height).
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4180
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4181
    self depth >= anImage depth ifTrue:[
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4182
        anImage depth <= 12 ifTrue:[
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4183
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4184
            "/ if my depth is greater, all colors can be represented,
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4185
            "/ and the loop can be done over pixel values ...
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4186
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4187
            colorMap isNil ifTrue:[
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4188
                map := Array new:(1 bitShift:anImage depth).
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4189
                1 to:map size do:[:i |
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4190
                    clr := anImage colorFromValue:(i - 1).
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4191
                    map at:i put:(self valueFromColor:clr).
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4192
                ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4193
            ].
1665
e0329f98904d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1664
diff changeset
  4194
            mappedRowPixels := self pixelArraySpecies new:width.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4195
            0 to:height-1 do:[:row |
1667
975687991916 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1665
diff changeset
  4196
                anImage rowAt:row into:mappedRowPixels startingAt:1.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4197
                map notNil ifTrue:[
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4198
                    1 to:width do:[:i |
1667
975687991916 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1665
diff changeset
  4199
                        mappedRowPixels at:i put:(map at:(mappedRowPixels at:i)+1)
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4200
                    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4201
                ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4202
                self rowAt:row putAll:mappedRowPixels
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4203
            ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4204
            ^ self
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4205
        ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4206
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4207
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4208
    anImage colorsFromX:0 y:0 toX:(width-1) y:(height-1) do:[:x :y :clr |
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4209
        self atX:x y:y put:clr
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4210
    ].
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4211
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4212
    "
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4213
     |i i2 i4 i8 i16 i24|
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4214
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4215
     i := Image fromFile:'bitmaps/SBrowser.xbm'.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4216
     i inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4217
     i2 := Depth2Image fromImage:i.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4218
     i2 inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4219
     i4 := Depth4Image fromImage:i.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4220
     i4 inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4221
     i8 := Depth8Image fromImage:i.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4222
     i8 inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4223
     i24 := Depth24Image fromImage:i.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4224
     i24 inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4225
    "
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4226
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4227
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4228
     |i i24|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4229
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4230
     i := Image fromFile:'bitmaps/gifImages/garfield.gif'.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4231
     Transcript showCR:(
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4232
        Time millisecondsToRun:[
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4233
            i24 := Depth24Image fromImage:i.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4234
        ]
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4235
     ).
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4236
     i24 inspect.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4237
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4238
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4239
     |i i24|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4240
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4241
     i := Image fromFile:'bitmaps/gifImages/garfield.gif'.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4242
     MessageTally spyOn:[
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4243
        i24 := Depth24Image fromImage:i.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4244
     ]
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4245
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4246
1667
975687991916 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1665
diff changeset
  4247
    "Modified: 24.4.1997 / 21:54:39 / cg"
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4248
!
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4249
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4250
fromSubImage:anImage in:aRectangle
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4251
    "setup the receiver from another image, extracting a rectangular
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4252
     area. Color precision may be lost, if conversion is from a higher depth
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4253
     image. For palette & rgb images, this may fail if a color cannot be
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4254
     represented.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4255
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4256
     WARNING:
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4257
       This implementation is a slow fallback (the loop over the
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4258
       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
  4259
       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
  4260
       of creating a subImage with the same depth & palette."
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4261
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4262
    |x0 y0|
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4263
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4264
    width := aRectangle width + 1.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4265
    height := aRectangle height + 1.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4266
    bytes := ByteArray uninitializedNew:(self bytesPerRow * height).
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4267
    bitsPerSample := self bitsPerSample.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4268
    samplesPerPixel := self samplesPerPixel.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4269
    self colormapFromImage:anImage.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4270
    x0 := aRectangle left.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4271
    y0 := aRectangle top.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4272
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4273
    ((photometric == anImage photometric)
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4274
    and:[self bitsPerPixel = anImage bitsPerPixel
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4275
    and:[colorMap = anImage colorMap]]) ifTrue:[
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4276
        "/ can do it by value
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4277
        anImage valuesFromX:x0  y:y0 
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4278
                        toX:aRectangle right y:aRectangle bottom 
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4279
                         do:[:x :y :pixelValue |
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4280
            self pixelAtX:x-x0 y:y-y0 put:pixelValue.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4281
        ]
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4282
    ] ifFalse:[
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4283
        "/ must do it by colors
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4284
        anImage colorsFromX:x0  y:y0 
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4285
                        toX:aRectangle right y:aRectangle bottom 
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4286
                         do:[:x :y :clr |
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4287
            self atX:x-x0 y:y-y0 putColor:clr.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4288
        ]
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4289
    ].
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4290
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4291
    "
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4292
     |i i2 i4 i8 i16 i24|
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4293
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4294
     i := Image fromFile:'bitmaps/garfield.gif'.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4295
     i inspect.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4296
     i4 := Depth4Image fromSubImage:i in:(300@160 corner:340@200).
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4297
     i4 inspect.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4298
     i8 := Depth8Image fromSubImage:i in:(300@160 corner:340@200).
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4299
     i8 inspect.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4300
     i24 := Depth24Image fromSubImage:i in:(300@160 corner:340@200).
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4301
     i24 inspect.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4302
    "
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4303
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4304
    "Created: 20.9.1995 / 01:06:02 / claus"
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4305
    "Modified: 20.9.1995 / 10:15:37 / claus"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4306
    "Modified: 24.4.1997 / 17:25:48 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4307
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4308
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4309
monochromeOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4310
    "return a monochrome device image of the receiver for aDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4311
     (monochrome, even if device supports colors)"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4312
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4313
    ((aDevice == device) and:[monoDeviceForm notNil]) ifTrue:[^ self].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4314
    (device notNil and:[aDevice ~~ device]) ifTrue:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4315
	"oops, I am already accociated to another device
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4316
	 - need a copy ...
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4317
	"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4318
	^ self copy monochromeOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4319
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4320
    monoDeviceForm := self asMonochromeFormOn:aDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4321
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4322
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4323
on:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4324
    "return an image with the same pixels as the receiver, but
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4325
     associated to aDevice. If the receiver is not yet bound to
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4326
     a device, this will be the receiver. Otherwise, a new image
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4327
     is returned."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4328
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4329
    ((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ self].
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  4330
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4331
    (device notNil and:[aDevice ~~ device]) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4332
	"oops, I am already accociated to another device
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4333
	 - need a copy ...
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4334
	"
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4335
	^ self copy on:aDevice
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4336
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4337
    deviceForm := self asFormOn:aDevice.
1057
410f0fec2872 oops - must register Image after assigning a deviceForm
Claus Gittinger <cg@exept.de>
parents: 1051
diff changeset
  4338
    device := aDevice.
410f0fec2872 oops - must register Image after assigning a deviceForm
Claus Gittinger <cg@exept.de>
parents: 1051
diff changeset
  4339
    Lobby register:self
410f0fec2872 oops - must register Image after assigning a deviceForm
Claus Gittinger <cg@exept.de>
parents: 1051
diff changeset
  4340
410f0fec2872 oops - must register Image after assigning a deviceForm
Claus Gittinger <cg@exept.de>
parents: 1051
diff changeset
  4341
    "Modified: 16.9.1996 / 21:02:33 / cg"
1496
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  4342
!
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  4343
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  4344
onDevice:aDevice
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  4345
    "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
  4346
     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
  4347
     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
  4348
     is returned."
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  4349
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  4350
    ^ self on:aDevice
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  4351
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  4352
    "Created: 28.3.1997 / 16:05:53 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4353
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4354
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4355
!Image methodsFor:'converting greyscale images'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4356
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4357
greyImageAsFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4358
    "return a thresholded grey-deviceForm from the grey image."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4359
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4360
    |pictureDepth nPlanes|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4361
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4362
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4363
    nPlanes := samplesPerPixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4364
    (nPlanes == 2) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4365
	'Image [info]: alpha plane ignored' infoPrintCR.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4366
	nPlanes := 1
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4367
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4368
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4369
    pictureDepth := bitsPerSample at:1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4370
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4371
    "monochrome is very easy ..."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4372
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4373
    (pictureDepth == 1) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4374
	^ Form width:width height:height fromArray:bytes on:aDevice
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4375
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4376
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4377
    (aDevice visualType == #TrueColor) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4378
	^ self greyImageAsTrueColorFormOn:aDevice
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4379
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4380
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  4381
"/    (aDevice visualType == #PseudoColor 
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  4382
"/    or:[aDevice visualType == #GrayScale
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  4383
"/    or:[aDevice visualType == #StaticColor]]) ifTrue:[
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  4384
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  4385
    "/ PseudoColor conversion also works for StaticColor,
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  4386
    "/ GrayScale and DirectColor; although possibly with suboptimal results
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  4387
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  4388
    ^ self greyImageAsPseudoFormOn:aDevice
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  4389
1175
5595569cfbd3 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 1170
diff changeset
  4390
    "Modified: 10.1.1997 / 17:52:49 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4391
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4392
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4393
greyImageAsPseudoFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4394
    "return an 8-bit pseudo Form from the grey image"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4395
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4396
    |wideBits pictureDepth f map  
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4397
     colorMap usedColors nUsed aColor 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4398
     nColors "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4399
     range id|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4400
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4401
    pictureDepth := bitsPerSample at:1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4402
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4403
    (#(2 4 8) includes:pictureDepth) ifFalse:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4404
	self error:'currently only depth-2, 4 or 8 supported'.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4405
	^ nil
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4406
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4407
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4408
    wideBits := ByteArray uninitializedNew:(width * height).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4409
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4410
    (pictureDepth == 8) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4411
	"for 8bits, we scan for used colors first;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4412
	 to avoid allocating too many colors"
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4413
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4414
	usedColors := bytes usedValues.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4415
	nUsed := usedColors max + 1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4416
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4417
	colorMap := Array new:nUsed.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4418
	photometric == #blackIs0 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4419
	    usedColors do:[:grey |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4420
		colorMap at:(grey + 1) put:(Color gray:(100.0 / 256.0 * grey))
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4421
	    ]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4422
	] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4423
	    usedColors do:[:grey |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4424
		colorMap at:(grey + 1) put:(Color gray:(100 - (100.0 / 256.0 * grey)))
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4425
	    ]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4426
	]
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4427
    ] ifFalse:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4428
	nColors := (1 bitShift:pictureDepth).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4429
	colorMap := Array new:nColors.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4430
	range := 100 / (nColors - 1) asFloat.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4431
	photometric == #blackIs0 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4432
	    1 to:nColors do:[:i |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4433
		colorMap at:i put:(Color gray:(i - 1) * range).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4434
	    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4435
	] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4436
	    1 to:nColors do:[:i |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4437
		colorMap at:(nColors - i + 1) put:(Color gray:(i - 1) * range).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4438
	    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4439
	].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4440
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4441
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4442
    "XXX should reduce 8->6->4->2 planes, if not all colors could be allocated"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4443
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4444
    "setup the translation map"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4445
    map := ByteArray uninitializedNew:256.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4446
    nColors := colorMap size.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4447
    1 to:nColors do:[:i |
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4448
	aColor := colorMap at:i.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4449
	aColor notNil ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4450
	    aColor := aColor on:aDevice.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4451
	    colorMap at:i put:aColor.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4452
	    id := aColor colorId.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4453
	    id notNil ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4454
		map at:i put:id
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4455
	    ] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4456
		map at:i put:0
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4457
	    ]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4458
	]
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4459
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4460
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4461
    "expand & translate"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4462
    bytes expandPixels:pictureDepth
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4463
		width:width 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4464
	       height:height
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4465
		 into:wideBits
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4466
	      mapping:map.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4467
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4468
    f := Form width:width height:height depth:8 on:aDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4469
    f isNil ifTrue:[^ nil].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4470
    f colorMap:colorMap. 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4471
    f initGC.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4472
    aDevice drawBits:wideBits depth:8 width:width height:height
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4473
		       x:0 y:0
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4474
		    into:(f id) x:0 y:0 width:width height:height with:(f gcId).
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4475
    ^ f
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  4476
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  4477
    "Modified: 28.5.1996 / 20:55:57 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4478
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  4479
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4480
greyImageAsTrueColorFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4481
    "return a true-color device-form for the grey-image receiver.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4482
     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
  4483
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4484
    |depth  
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  4485
     myDepth    "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  4486
     nColors    "{ Class: SmallInteger }"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4487
     colorValues
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  4488
     scaleDown 
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  4489
     scaleRed   "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  4490
     scaleGreen "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  4491
     scaleBlue  "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  4492
     redShift   "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  4493
     blueShift  "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  4494
     greenShift "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  4495
     form bestFormat usedDeviceDepth usedDeviceBitsPerPixel imageBits 
1175
5595569cfbd3 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 1170
diff changeset
  4496
     greyValue  "{ Class: SmallInteger }"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4497
     h          "{ Class: SmallInteger }"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4498
     w          "{ Class: SmallInteger }"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4499
     pixelArray newPixelArray i|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4500
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4501
    "/ this is a slow fallback method; this ought to be
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4502
    "/ redefined in DepthxImage for more performance.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4503
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4504
    depth := aDevice depth.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4505
    myDepth := self depth.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4506
    myDepth > 12 ifTrue:[
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4507
        self error:'unsupported trueColor depth in greyImageAsTrueColorFormOn:'.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4508
        ^ nil
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4509
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
  4510
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4511
    "/ compute scale to map from my pixels into devices range
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4512
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4513
    scaleDown := 1 bitShift:myDepth.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4514
    scaleRed := (1 bitShift:aDevice bitsRed).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4515
    scaleGreen := (1 bitShift:aDevice bitsGreen).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4516
    scaleBlue := (1 bitShift:aDevice bitsBlue).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4517
    redShift := aDevice shiftRed.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4518
    greenShift := aDevice shiftGreen.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4519
    blueShift := aDevice shiftBlue.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4520
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  4521
    "/ prepare the map
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  4522
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4523
    nColors := (1 bitShift:myDepth).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4524
    colorValues := Array new:nColors.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4525
    1 to:nColors do:[:i |
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4526
        |v gv bv rv nv|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4527
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4528
        "/ scale down to 0..1
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4529
        v := (i-1) / scaleDown.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4530
        rv := (v * scaleRed) truncated.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4531
        gv := (v * scaleGreen) truncated.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4532
        bv := (v * scaleBlue) truncated.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4533
        nv := rv bitShift:redShift.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4534
        nv := nv bitOr:(gv bitShift:greenShift).
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4535
        nv := nv bitOr:(bv bitShift:blueShift).
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4536
        colorValues at:i put:nv
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4537
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4538
    photometric == #whiteIs0 ifTrue:[
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4539
        "/ reverse the order; 0 is brightest
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4540
        colorValues reverse
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4541
    ].
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4542
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4543
    bestFormat := self bestSupportedImageFormatFor:aDevice.
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  4544
    usedDeviceDepth := bestFormat at:#depth.
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  4545
    usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4546
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4547
    "/ the temporary helper image is only needed to allow
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4548
    "/ the rowAt:putAll: calls below.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4549
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  4550
    i := (Image implementorForDepth:usedDeviceBitsPerPixel) new.
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  4551
    i width:width height:height.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4552
    imageBits := ByteArray new:(i bytesPerRow * height).
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4553
    i bits:imageBits.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4554
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4555
    "/ now, walk over the image and replace
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4556
    "/ colorMap indices by color values in the bits array
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4557
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4558
    h := height - 1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4559
    w := width - 1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4560
    pixelArray := self pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4561
    newPixelArray := i pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4562
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4563
    0 to:h do:[:y |
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4564
        self rowAt:y into:pixelArray.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4565
        0 to:w do:[:x |
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4566
            greyValue := pixelArray at:(x+1).
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4567
            newPixelArray at:(x+1) put:(colorValues at:greyValue + 1).
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4568
        ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4569
        i rowAt:y putAll:newPixelArray.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4570
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4571
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4572
    form := Form width:width height:height depth:usedDeviceDepth on:aDevice.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4573
    form isNil ifTrue:[^ nil].
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4574
    form initGC.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4575
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4576
    form 
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4577
        copyBitsFrom:imageBits bitsPerPixel:usedDeviceBitsPerPixel depth:usedDeviceDepth 
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4578
               width:width height:height 
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4579
                   x:0 y:0 toX:0 y:0. 
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4580
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4581
    ^ form
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4582
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4583
    "Created: 20.10.1995 / 22:05:10 / cg"
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  4584
    "Modified: 24.4.1997 / 23:11:16 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4585
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
  4586
48194c26a46c Initial revision
claus
parents:
diff changeset
  4587
!Image methodsFor:'converting palette images'!
48194c26a46c Initial revision
claus
parents:
diff changeset
  4588
48194c26a46c Initial revision
claus
parents:
diff changeset
  4589
paletteImageAsFormOn:aDevice
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4590
    "return a device-form for the palette-image receiver"
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4591
380
c5ffc6d48a9e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 379
diff changeset
  4592
    |type ddepth|
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4593
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4594
    ddepth := aDevice depth.
379
d74cdaa0adcb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
  4595
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4596
    aDevice hasGrayscales not ifTrue:[
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4597
	^ self asMonochromeFormOn:aDevice
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4598
    ].
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4599
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4600
    ((type := aDevice visualType) == #StaticGray) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4601
	ddepth == 8 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4602
	    ^ self paletteImageAsGray8FormOn:aDevice
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4603
	].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4604
	^ self asGrayFormOn:aDevice
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4605
    ].
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4606
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4607
    (type == #TrueColor) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4608
	DitherAlgorithm == #floydSteinberg ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4609
	    ddepth == 8 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4610
		self depth == 8 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4611
		    "/ use fixColor dither algorithm
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4612
		    ^ self asDitheredTrueColor8FormOn:aDevice
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4613
		]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4614
	    ]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4615
	].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4616
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4617
	^ self paletteImageAsTrueColorFormOn:aDevice
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4618
    ].
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  4619
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  4620
    "/ the PseudoColor conversion also works for
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  4621
    "/ StaticColor, GrayScale & DirectColor; although possibly with suboptimal results
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  4622
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  4623
    ^ self paletteImageAsPseudoFormOn:aDevice
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  4624
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  4625
    "Modified: 14.6.1996 / 19:31:01 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4626
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  4627
48194c26a46c Initial revision
claus
parents:
diff changeset
  4628
paletteImageAsPseudoFormOn:aDevice
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4629
    "return a pseudo-deviceForm from the palette image."
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4630
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4631
    |tempImage d temp8|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4632
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4633
    d := self depth.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4634
    (#(1 2 4 8) includes:d) ifTrue:[ 
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4635
	"
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4636
	 fallback code for some depth's:
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4637
	 create a temporary Depth8Image and use its conversion method
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4638
	"
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4639
	temp8 := ByteArray uninitializedNew:(width * height).
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4640
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4641
	bytes expandPixels:d      
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4642
		     width:width 
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4643
		   height:height
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4644
		     into:temp8
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4645
		  mapping:nil.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4646
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4647
	tempImage := Image width:width height:height depth:8 fromArray:temp8.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4648
	tempImage colorMap:colorMap.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4649
	^ tempImage paletteImageAsPseudoFormOn:aDevice
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4650
    ].
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  4651
    ^ self subclassResponsibility
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4652
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  4653
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4654
paletteImageAsTrueColorFormOn:aDevice
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4655
    "return a true-color device-form for the palette-image receiver."
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4656
209
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  4657
    |depth 
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  4658
     nColors "{ Class: SmallInteger }"
1605
64151392ff64 added generic #paletteImageAsTrueColorForm implementation
Claus Gittinger <cg@exept.de>
parents: 1595
diff changeset
  4659
     w       "{ Class: SmallInteger }"
64151392ff64 added generic #paletteImageAsTrueColorForm implementation
Claus Gittinger <cg@exept.de>
parents: 1595
diff changeset
  4660
     h       "{ Class: SmallInteger }"
64151392ff64 added generic #paletteImageAsTrueColorForm implementation
Claus Gittinger <cg@exept.de>
parents: 1595
diff changeset
  4661
     pixel   "{ Class: SmallInteger }"
64151392ff64 added generic #paletteImageAsTrueColorForm implementation
Claus Gittinger <cg@exept.de>
parents: 1595
diff changeset
  4662
     rgbVal  "{ Class: SmallInteger }"
64151392ff64 added generic #paletteImageAsTrueColorForm implementation
Claus Gittinger <cg@exept.de>
parents: 1595
diff changeset
  4663
     dstIdx  "{ Class: SmallInteger }"
209
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  4664
     colorValues 
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4665
     scaleRed scaleGreen scaleBlue redShift greenShift blueShift
194
Claus Gittinger <cg@exept.de>
parents: 193
diff changeset
  4666
     form imageBits bestFormat usedDeviceDepth usedDeviceBitsPerPixel 
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4667
     n i pixelArray newPixelArray|
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4668
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4669
    "/ this is a slow fallback method; this ought to be
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4670
    "/ redefined in DepthxImage for more performance.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4671
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4672
    depth := aDevice depth.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4673
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4674
    "/ gather r/g/b values for all colors in the map ...
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4675
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4676
    nColors := colorMap size.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4677
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4678
    "/ precompute scales to map from 0..100 into devices range
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4679
    "/ (this may be different for the individual components)
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4680
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4681
    scaleRed := ((1 bitShift:aDevice bitsRed) - 1) / 100.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4682
    scaleGreen := ((1 bitShift:aDevice bitsGreen) - 1) / 100.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4683
    scaleBlue := ((1 bitShift:aDevice bitsBlue) - 1) / 100.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4684
    redShift := aDevice shiftRed.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4685
    greenShift := aDevice shiftGreen.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4686
    blueShift := aDevice shiftBlue.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4687
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4688
    colorValues := Array uninitializedNew:nColors.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4689
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4690
    1 to:nColors do:[:index |
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4691
        |clr rv gv bv v "{ Class: SmallInteger }" |
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4692
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4693
        clr := colorMap at:index.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4694
        clr notNil ifTrue:[
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4695
            rv := (clr red * scaleRed) rounded.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4696
            gv := (clr green * scaleGreen) rounded.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4697
            bv := (clr blue * scaleBlue) rounded.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4698
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4699
            v := rv bitShift:redShift.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4700
            v := v bitOr:(gv bitShift:greenShift).
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4701
            v := v bitOr:(bv bitShift:blueShift).
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4702
            colorValues at:index put:v.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4703
"/ clr print. ' ' print.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4704
"/ rv print. ' ' print. gv print. ' ' print. bv print. ' ' print.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4705
"/ ' -> ' print. v printNL.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4706
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4707
        ]
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4708
    ].
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4709
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4710
    bestFormat := self bestSupportedImageFormatFor:aDevice.
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  4711
    usedDeviceDepth := bestFormat at:#depth.
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  4712
    usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4713
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4714
    "/ the temporary helper image is only needed to allow
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4715
    "/ the rowAt:putAll: calls below.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4716
1665
e0329f98904d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1664
diff changeset
  4717
    i := (Image implementorForDepth:usedDeviceBitsPerPixel) new.
e0329f98904d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1664
diff changeset
  4718
    i width:width height:height.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4719
    imageBits := ByteArray new:(i bytesPerRow * height).
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4720
    i bits:imageBits.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4721
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4722
    "/ now, walk over the image and replace
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4723
    "/ colorMap indices by color values in the bits array
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4724
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4725
    h := height - 1.
1605
64151392ff64 added generic #paletteImageAsTrueColorForm implementation
Claus Gittinger <cg@exept.de>
parents: 1595
diff changeset
  4726
    w := width - 1.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4727
    pixelArray := self pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4728
    newPixelArray := i pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4729
1605
64151392ff64 added generic #paletteImageAsTrueColorForm implementation
Claus Gittinger <cg@exept.de>
parents: 1595
diff changeset
  4730
    0 to:h do:[:y |
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4731
        self rowAt:y into:pixelArray.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4732
        0 to:w do:[:x |
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4733
            pixel := pixelArray at:(x+1).
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4734
            newPixelArray at:(x+1) put:(colorValues at:pixel + 1).
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4735
        ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4736
        i rowAt:y putAll:newPixelArray.
1605
64151392ff64 added generic #paletteImageAsTrueColorForm implementation
Claus Gittinger <cg@exept.de>
parents: 1595
diff changeset
  4737
    ].
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4738
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4739
    form := Form width:width height:height depth:usedDeviceDepth on:aDevice.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4740
    form isNil ifTrue:[^ nil].
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4741
    form initGC.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4742
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4743
    form 
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4744
        copyBitsFrom:imageBits bitsPerPixel:usedDeviceBitsPerPixel depth:usedDeviceDepth 
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4745
               width:width height:height 
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  4746
                   x:0 y:0 toX:0 y:0. 
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4747
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4748
    ^ form
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4749
1665
e0329f98904d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1664
diff changeset
  4750
    "Modified: 24.4.1997 / 20:43:34 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4751
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
  4752
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4753
!Image methodsFor:'converting rgb images'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4754
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4755
asDitheredTrueColor8FormOn:aDevice
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4756
    "convert an rgb image to a dithered depth8-form on aDevice.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4757
     Return the device-form."
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4758
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4759
    |fixColors pixel
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4760
     dstIdx     "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4761
     shiftRed   "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4762
     shiftGreen "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4763
     shiftBlue  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4764
     nRed    "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4765
     nGreen  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4766
     nBlue   "{ Class: SmallInteger }"|
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4767
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4768
    shiftRed := aDevice shiftRed.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4769
    shiftGreen := aDevice shiftGreen.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4770
    shiftBlue := aDevice shiftBlue.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4771
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4772
    nRed := (1 bitShift:aDevice bitsRed).
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4773
    nGreen := (1 bitShift:aDevice bitsGreen).
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4774
    nBlue := (1 bitShift:aDevice bitsBlue).
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4775
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4776
    fixColors := Array new:(nRed * nGreen * nBlue).
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4777
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4778
    dstIdx := 1.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4779
    0 to:nRed - 1 do:[:sR |
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4780
	0 to:nGreen - 1 do:[:sG |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4781
	    0 to:nBlue - 1 do:[:sB |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4782
		pixel := (sR bitShift:shiftRed)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4783
			 + (sG bitShift:shiftGreen)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4784
			 + (sB bitShift:shiftBlue).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4785
		fixColors at:dstIdx put:(Color colorId:(pixel)).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4786
		dstIdx := dstIdx + 1
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4787
	    ]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4788
	]
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4789
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4790
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4791
    ^ self
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4792
	asFloydSteinbergDitheredDepth8FormOn:aDevice 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4793
	colors:fixColors 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4794
	nRed:nRed nGreen:nGreen nBlue:nBlue
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4795
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4796
    "Modified: 14.6.1996 / 17:18:57 / cg"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4797
    "Created: 14.6.1996 / 17:23:52 / cg"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4798
!
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4799
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4800
rgbImageAsFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4801
    "convert am rgb image to a device-form on aDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4802
     Return the device-form."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4803
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4804
    |visual|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4805
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4806
    visual := aDevice visualType.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4807
    (visual == #StaticGray) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4808
	^ self asGrayFormOn:aDevice
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4809
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4810
    (visual == #TrueColor) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4811
	^ self rgbImageAsTrueColorFormOn:aDevice
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4812
    ].
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  4813
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  4814
    "/ PseudoColor conversion also works for StaticColor, GrayScale
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  4815
    "/ and DirectColor displays; although possibly with suboptimal results
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  4816
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4817
    ^ self rgbImageAsPseudoFormOn:aDevice
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4818
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  4819
    "Modified: 14.6.1996 / 19:30:06 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4820
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4821
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4822
rgbImageAsPseudoFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4823
    "return a pseudocolor form from the rgb-picture"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4824
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  4825
    |n     "{ Class: SmallInteger }"
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  4826
     depth "{ Class: SmallInteger }"
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  4827
     palette f|
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  4828
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  4829
    (depth := self depth) <= 8 ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4830
	"/ simulate it via a temporary palette image
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4831
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4832
	palette := Array new:(1 bitShift:depth).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4833
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4834
	n := (1 bitShift:depth)-1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4835
	0 to:n do:[:pixelValue |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4836
	    palette at:(pixelValue+1) put:(self colorFromValue:pixelValue)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4837
	].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4838
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4839
	colorMap := palette.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4840
	photometric := #palette.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4841
	f := self paletteImageAsPseudoFormOn:aDevice.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4842
	colorMap := nil.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4843
	photometric := #rgb.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4844
	^ f
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  4845
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  4846
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4847
    ^ self subclassResponsibility
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  4848
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  4849
    "Modified: 8.6.1996 / 10:58:25 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4850
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4851
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4852
rgbImageAsTrueColorFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4853
    "return a truecolor form from the rgb-picture."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4854
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4855
    |bestFormat usedDeviceDepth usedDeviceBitsPerPixel
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4856
     form|
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4857
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4858
    bestFormat := self bestSupportedImageFormatFor:aDevice.
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  4859
    usedDeviceDepth := bestFormat at:#depth.
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  4860
    usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4861
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4862
    "/ 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
  4863
    usedDeviceBitsPerPixel == 15 ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4864
	usedDeviceBitsPerPixel := 16
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  4865
    ].
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  4866
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4867
    "/
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4868
    "/ only the trivial case, where the depths match
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4869
    "/ is handled here; conversions are supposed to
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4870
    "/ be done in concrete subclasses (see D24Image)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4871
    "/
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4872
    self bitsPerPixel == usedDeviceBitsPerPixel ifFalse:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4873
	'Image [warning]: unimplemented trueColor depth in rgbImageAsTrueColorFormOn: ' errorPrint. self bitsPerPixel errorPrintCR.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4874
	^ self asMonochromeFormOn:aDevice
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4875
    ].
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4876
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4877
    form := Form width:width height:height depth:usedDeviceDepth on:aDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4878
    form isNil ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4879
	'Image [warning]: display bitmap creation failed' errorPrintCR.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4880
	^ nil
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4881
    ].
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4882
    form initGC.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4883
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4884
    form 
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4885
	copyBitsFrom:bytes bitsPerPixel:usedDeviceBitsPerPixel depth:usedDeviceDepth 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4886
	       width:width height:height 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4887
		   x:0 y:0 toX:0 y:0. 
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4888
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4889
    ^ form
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  4890
1175
5595569cfbd3 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 1170
diff changeset
  4891
    "Modified: 10.1.1997 / 17:53:23 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4892
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4893
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4894
!Image methodsFor:'copying'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4895
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4896
postCopy
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  4897
    "redefined to also copy the pixels and the colorMap
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  4898
     and clear out any device handles in the copy."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  4899
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4900
    bytes := bytes copy.
916
ddc18f6280ed dont deepCopy the colorMap
Claus Gittinger <cg@exept.de>
parents: 906
diff changeset
  4901
    colorMap := colorMap copy.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4902
    device := deviceForm := monoDeviceForm := fullColorDeviceForm := nil
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  4903
916
ddc18f6280ed dont deepCopy the colorMap
Claus Gittinger <cg@exept.de>
parents: 906
diff changeset
  4904
    "Modified: 5.7.1996 / 13:16:04 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4905
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4906
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4907
!Image methodsFor:'displaying'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4908
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  4909
displayFilledOn:aGC
759
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  4910
    "display the receiver as an opaque image.
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  4911
     This allows Images to be wrapped by a FillingWrapper"
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  4912
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  4913
    aGC displayOpaqueForm:self x:0 y:0.
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  4914
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  4915
    "Created: 29.5.1996 / 10:34:18 / cg"
759
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  4916
    "Modified: 29.5.1996 / 10:52:36 / cg"
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  4917
!
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  4918
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4919
displayOn:aGC at:aPoint
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  4920
    "draw the receiver in the graphicsContext, aGC.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4921
     Smalltalk-80 compatibility"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4922
672
01d7c8b9d2e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  4923
    self displayOn:aGC x:aPoint x y:aPoint y.
01d7c8b9d2e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  4924
01d7c8b9d2e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  4925
    "Modified: 12.5.1996 / 20:16:38 / cg"
01d7c8b9d2e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  4926
!
01d7c8b9d2e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  4927
01d7c8b9d2e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  4928
displayOn:aGC x:x y:y
01d7c8b9d2e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  4929
    "draw the receiver in the graphicsContext, aGC.
01d7c8b9d2e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  4930
     Smalltalk-80 compatibility"
01d7c8b9d2e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  4931
01d7c8b9d2e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  4932
    aGC displayForm:self x:x y:y.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  4933
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  4934
    "Modified: 23.4.1996 / 11:12:31 / cg"
672
01d7c8b9d2e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  4935
    "Created: 12.5.1996 / 20:14:31 / cg"
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  4936
!
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  4937
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  4938
displayOpaqueOn:aGC x:x y:y
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  4939
    "draw the receiver in the graphicsContext, aGC.
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  4940
     Smalltalk-80 compatibility"
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  4941
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  4942
    aGC displayOpaqueForm:self x:x y:y.
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  4943
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  4944
    "Modified: 23.4.1996 / 11:12:31 / cg"
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  4945
    "Created: 22.10.1996 / 16:35:49 / cg"
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  4946
!
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  4947
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  4948
displayStrokedOn:aGC
759
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  4949
    "display the receiver as an non opaque image.
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  4950
     This allows Images to be wrapped by a StrokingWrapper"
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  4951
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  4952
    aGC displayForm:self x:0 y:0.
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  4953
759
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  4954
    "Created: 29.5.1996 / 10:34:18 / cg"
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  4955
    "Modified: 29.5.1996 / 10:52:30 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4956
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4957
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4958
!Image methodsFor:'dither helpers'!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4959
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4960
burkesDitheredMonochromeBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4961
    "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
  4962
     Works for any source depths / photometric"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4963
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4964
    |dstIndex        "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4965
     nextDst         "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4966
     bytesPerMonoRow "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4967
     monoBits greyValues
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4968
     errorArray
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4969
     errorArray1
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4970
     e t
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4971
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4972
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4973
     bitCnt          "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4974
     byte            "{Class: SmallInteger }" 
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4975
     grey|
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4976
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4977
    self depth > 12 ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4978
	^ self floydSteinbergDitheredMonochromeBits
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4979
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4980
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4981
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4982
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4983
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4984
    bytesPerMonoRow := (w + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4985
    monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4986
    (monoBits isNil or:[bytes isNil]) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  4987
	^ nil
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4988
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4989
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4990
    errorArray := Array new:(w+4).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4991
    errorArray1 := Array new:(w+4) withAll:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4992
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4993
    dstIndex := 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4994
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4995
    "/ 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
  4996
    "/ use table-value in loop
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4997
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4998
    greyValues := self greyMapForRange:(255*1024).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4999
    
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5000
    0 to:(h-1) do:[:y |
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5001
	nextDst := dstIndex + bytesPerMonoRow.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5002
	byte := 0.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5003
	bitCnt := 8.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5004
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5005
	t := errorArray.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5006
	errorArray := errorArray1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5007
	errorArray1 := t.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5008
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5009
	errorArray1 atAllPut:0.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5010
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5011
	self valuesAtY:y from:0 to:(w-1) do:[:x :pixel |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5012
	    |eP "{Class: SmallInteger }" 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5013
	     eD 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5014
	     eI "{Class: SmallInteger }" 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5015
	     xE "{Class: SmallInteger }"
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5016
	     xN "{Class: SmallInteger }" |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5017
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5018
	    "/ get the colors grey value [0 .. 1]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5019
	    grey := greyValues at:(pixel + 1).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5020
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5021
	    "/ adjust error
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5022
	    xE := x + 2 + 1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5023
	    grey := (grey + (errorArray at:xE)).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5024
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5025
	    byte := byte bitShift:1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5026
	    grey > (127*1024) ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5027
		byte := byte bitOr:1.      "/ white
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5028
		e := grey - (255*1024)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5029
	    ] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5030
		e := grey                  "/ black
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5031
	    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5032
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5033
	    e ~= 0 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5034
		"/ distribute the error:
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5035
		"/                  XX  8  4
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5036
		"/             2  4  8  4  2
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5037
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5038
		eD := e.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5039
		eI := e // 32.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5040
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5041
		eP := eI * 8. eD := eD - eP.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5042
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5043
		xN := xE + 1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5044
		errorArray at:xN put:(errorArray at:xN) + eP.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5045
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5046
		eD := eD - eP.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5047
		errorArray1 at:xE put:(errorArray1 at:xE) + eP.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5048
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5049
		eP := eI * 4. eD := eD - eP.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5050
		xN := xE + 2.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5051
		errorArray at:xN put:(errorArray at:xN) + eP.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5052
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5053
		eD := eD - eP.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5054
		xN := xE - 1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5055
		errorArray1 at:xN put:(errorArray1 at:xN) + eP.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5056
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5057
		eD := eD - eP.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5058
		xN := xE + 1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5059
		errorArray1 at:xN put:(errorArray1 at:xN) + eP.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5060
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5061
		eP := eI * 2. eD := eD - eP.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5062
		xN := xE - 2.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5063
		errorArray1 at:xN put:(errorArray1 at:xN) + eP.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5064
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5065
		eD := eD.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5066
		xN := xE + 2.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5067
		errorArray1 at:xN put:(errorArray1 at:xN) + eP.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5068
	    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5069
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5070
	    bitCnt := bitCnt - 1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5071
	    bitCnt == 0 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5072
		monoBits at:dstIndex put:byte.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5073
		dstIndex := dstIndex + 1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5074
		byte := 0.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5075
		bitCnt := 8.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5076
	    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5077
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5078
	].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5079
	bitCnt ~~ 8 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5080
	    byte := byte bitShift:bitCnt.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5081
	    monoBits at:dstIndex put:byte.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5082
	].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5083
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5084
	dstIndex := nextDst.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5085
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5086
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5087
    ^ monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5088
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5089
    "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
  5090
    "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
  5091
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5092
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5093
floydSteinbergDitheredBitsDepth:depth
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5094
    "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
  5095
     Works for any source depths / photometric, 
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5096
     but 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
  5097
     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
  5098
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5099
    |dstIndex        "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5100
     nextDst         "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5101
     bytesPerOutRow  "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5102
     outBits greyValues greyErrors greyPixels greyLevels
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5103
     errorArray
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5104
     nextErrorArray
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  5105
     t
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5106
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5107
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5108
     bitCnt          "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5109
     byte            "{Class: SmallInteger }" 
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  5110
     grey
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5111
     eR eRB eB eLB |
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
    depth > 8 ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5114
	self error:'unimplemented conversion'.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5115
	^ nil
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5116
    ].
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
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5119
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5120
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5121
    bytesPerOutRow := ((w * depth) + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5122
    outBits := ByteArray uninitializedNew:(bytesPerOutRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5123
    (outBits isNil or:[bytes isNil]) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5124
	^ nil
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5125
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5126
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5127
    greyLevels := (1 bitShift:depth) - 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5128
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5129
    errorArray := Array new:w+2.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5130
    nextErrorArray := Array new:w+2.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5131
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5132
    nextErrorArray atAllPut:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5133
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5134
    dstIndex := 1.
828
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  5135
    bitCnt := 8.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5136
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5137
    self depth <= 12 ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5138
	"/ fetch scaled brightness values outside of loop into a table;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5139
	"/ use table-value in loop
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5140
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5141
	greyValues := self greyMapForRange:(greyLevels).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5142
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5143
	greyPixels := greyValues collect:[:v | v isNil ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5144
						   0
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5145
					       ] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5146
						   v truncated]].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5147
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5148
	greyPixels := ByteArray withAll:greyPixels.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5149
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5150
	greyErrors := greyValues collect:[:v | v isNil ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5151
						   0
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5152
					       ] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5153
						   ((v - v truncated) * 1024) truncated
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5154
					       ]].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5155
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5156
	0 to:(h-1) do:[:y |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5157
	    nextDst := dstIndex + bytesPerOutRow.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5158
	    byte := 0.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5159
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5160
	    t := errorArray.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5161
	    errorArray := nextErrorArray.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5162
	    nextErrorArray := t.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5163
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5164
	    nextErrorArray atAllPut:0.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5165
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5166
	    self valuesAtY:y from:0 to:(w-1) do:[:x :value |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5167
		|e     "{ Class: SmallInteger }"
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5168
		 pixel "{ Class: SmallInteger }"
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5169
		 error "{ Class: SmallInteger }"
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5170
		 e16   "{ Class: SmallInteger }"
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5171
		 xE    "{ Class: SmallInteger }" 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5172
		 xN    "{ Class: SmallInteger }" |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5173
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5174
		pixel := greyPixels at:(value + 1).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5175
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5176
		"/ adjust error
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5177
		xE := x + 2.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5178
		error := (greyErrors at:(value + 1)) + (errorArray at:xE).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5179
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5180
		byte := byte bitShift:depth.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5181
		error > 512 "0.5" ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5182
		    pixel := pixel + 1.      
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5183
		    e := error - 1024 "1.0"
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5184
		] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5185
		    e := error              
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5186
		].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5187
		byte := byte bitOr:pixel.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5188
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5189
		e ~= 0 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5190
		    e16 := e // 16.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5191
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5192
		    eR  := e16 * 7.              "/ 7/16 to right
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5193
		    eRB := e16 * 1.              "/ 1/16 to right below
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5194
		    eB  := e16 * 5.              "/ 5/16 to below
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5195
		    eLB := e - eR - eRB - eB.  "/ 3/16 to left below
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5196
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5197
		    xN := xE + 1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5198
		    eR ~= 0 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5199
			errorArray     at:xN put:(errorArray at:xN) + eR.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5200
		    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5201
		    eRB ~= 0 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5202
			nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5203
		    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5204
		    eB ~= 0 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5205
			nextErrorArray at:xE put:(nextErrorArray at:xE) + eB.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5206
		    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5207
		    eLB ~= 0 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5208
			xN := xE - 1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5209
			nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5210
		    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5211
		].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5212
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5213
		bitCnt := bitCnt - depth.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5214
		bitCnt == 0 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5215
		    outBits at:dstIndex put:byte.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5216
		    dstIndex := dstIndex + 1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5217
		    byte := 0.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5218
		    bitCnt := 8.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5219
		].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5220
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5221
	    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5222
	    bitCnt ~~ 8 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5223
		byte := byte bitShift:bitCnt.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5224
		outBits at:dstIndex put:byte.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5225
		bitCnt := 8.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5226
	    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5227
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5228
	    dstIndex := nextDst.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5229
	].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5230
    ] ifFalse:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5231
	0 to:(h-1) do:[:y |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5232
	    nextDst := dstIndex + bytesPerOutRow.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5233
	    byte := 0.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5234
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5235
	    t := errorArray.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5236
	    errorArray := nextErrorArray.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5237
	    nextErrorArray := t.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5238
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5239
	    nextErrorArray atAllPut:0.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5240
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5241
	    self colorsAtY:y from:0 to:(w-1) do:[:x :clr |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5242
		|e     "{ Class: SmallInteger }"
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5243
		 pixel "{ Class: SmallInteger }"
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5244
		 error "{ Class: SmallInteger }"
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5245
		 e16   "{ Class: SmallInteger }"
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5246
		 xE    "{ Class: SmallInteger }" 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5247
		 xN    "{ Class: SmallInteger }" |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5248
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5249
		grey := (clr brightness * greyLevels).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5250
		pixel := grey truncated.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5251
		error := ((grey - pixel) * 1024) truncated.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5252
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5253
		"/ adjust error
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5254
		xE := x + 2.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5255
		error := error + (errorArray at:xE).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5256
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5257
		byte := byte bitShift:depth.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5258
		error > 512 "0.5" ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5259
		    pixel := pixel + 1.      
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5260
		    e := error - 1024 "1.0"
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5261
		] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5262
		    e := error              
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5263
		].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5264
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5265
		byte := byte bitOr:pixel.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5266
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5267
		e ~= 0 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5268
		    e16 := e // 16.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5269
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5270
		    eR  := e16 * 7.              "/ 7/16 to right
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5271
		    eRB := e16 * 1.              "/ 1/16 to right below
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5272
		    eB  := e16 * 5.              "/ 5/16 to below
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5273
		    eLB := e - eR - eRB - eB.  "/ 3/16 to left below
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5274
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5275
		    xN := xE + 1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5276
		    eR ~= 0 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5277
			errorArray     at:xN put:(errorArray at:xN) + eR.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5278
		    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5279
		    eRB ~= 0 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5280
			nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5281
		    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5282
		    eB ~= 0 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5283
			nextErrorArray at:xE put:(nextErrorArray at:xE) + eB.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5284
		    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5285
		    eLB ~= 0 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5286
			xN := xE - 1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5287
			nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5288
		    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5289
		].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5290
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5291
		bitCnt := bitCnt - depth.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5292
		bitCnt == 0 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5293
		    outBits at:dstIndex put:byte.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5294
		    dstIndex := dstIndex + 1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5295
		    byte := 0.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5296
		    bitCnt := 8.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5297
		].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5298
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5299
	    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5300
	    bitCnt ~~ 8 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5301
		byte := byte bitShift:bitCnt.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5302
		outBits at:dstIndex put:byte.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5303
		bitCnt := 8.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5304
	    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5305
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5306
	    dstIndex := nextDst.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5307
	].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5308
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5309
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5310
    ^ outBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5311
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5312
    "Created: 10.6.1996 / 13:28:22 / cg"
828
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  5313
    "Modified: 11.6.1996 / 00:13:38 / cg"
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5314
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5315
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5316
floydSteinbergDitheredDepth8BitsColors:colors
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5317
    "return a floyd-steinberg dithered bitmap from the receiver picture,
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5318
     which must be a depth-8 image. 
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5319
     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
  5320
     (which need not be a colorCubes colors)."
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5321
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5322
    |pseudoBits  
882
a3181765132b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 879
diff changeset
  5323
     rgbBytes 
a3181765132b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 879
diff changeset
  5324
     ditherRGBBytes ditherColors
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5325
     w       "{Class: SmallInteger }"
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5326
     h       "{Class: SmallInteger }"
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5327
     index   "{Class: SmallInteger }"
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5328
     fixR    "{Class: SmallInteger }"
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5329
     fixG    "{Class: SmallInteger }"
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5330
     fixB    "{Class: SmallInteger }"
888
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5331
     ditherIds failed map lastColor colorsByDistance qScramble
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5332
     clrLookup lookupPos
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5333
     error clr|
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5334
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5335
    self depth ~~ 8 ifTrue:[^ nil].
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5336
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5337
    "/
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5338
    "/ collect color components as integer values (for integer arithmetic)
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5339
    "/
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5340
    rgbBytes := ByteArray uninitializedNew:256 * 3.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5341
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5342
    photometric == #palette ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5343
	lastColor := colorMap size - 1
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5344
    ] ifFalse:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5345
	lastColor := 255.
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5346
    ].
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5347
    index := 1.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5348
    0 to:lastColor do:[:pix |
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5349
	clr := self colorFromValue:pix.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5350
	rgbBytes at:index put:(clr redByte).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5351
	rgbBytes at:index+1 put:(clr greenByte).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5352
	rgbBytes at:index+2 put:(clr blueByte).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5353
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5354
	index := index + 3.
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5355
    ].
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5356
888
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5357
    "/ collect valid ditherColors ...
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5358
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5359
    ditherColors := colors select:[:clr | clr notNil].
888
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5360
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5361
    "/ ... and sort by manhatten distance from black
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5362
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5363
    qScramble := #(
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5364
		"/  2rX00X00X00X00
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5365
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5366
		    2r000000000000    "/ 0
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5367
		    2r000000000100    "/ 1
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5368
		    2r000000100000    "/ 2
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5369
		    2r000000100100    "/ 3
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5370
		    2r000100000000    "/ 4
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5371
		    2r000100000100    "/ 5
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5372
		    2r000100100000    "/ 6
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5373
		    2r000100100100    "/ 7
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5374
		    2r100000000000    "/ 8
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5375
		    2r100000000100    "/ 9
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5376
		    2r100000100000    "/ a
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5377
		    2r100000100100    "/ b
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5378
		    2r100100000000    "/ c
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5379
		    2r100100000100    "/ d
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5380
		    2r100100100000    "/ e
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5381
		    2r100100100100    "/ f
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5382
		  ).
888
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5383
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5384
    ditherColors := ditherColors sort:[:a :b |
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5385
				|cr "{Class: SmallInteger }"
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5386
				 cg "{Class: SmallInteger }"
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5387
				 cb "{Class: SmallInteger }"
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5388
				 i1 "{Class: SmallInteger }"
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5389
				 i2 "{Class: SmallInteger }"|
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5390
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5391
				cr := a redByte.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5392
				cg := a greenByte.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5393
				cb := a blueByte.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5394
				i1 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5395
				i1 := i1 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5396
				i1 := i1 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5397
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5398
				cr := b redByte.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5399
				cg := b greenByte.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5400
				cb := b blueByte.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5401
				i2 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5402
				i2 := i2 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5403
				i2 := i2 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5404
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5405
				i1 < i2
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5406
		    ].
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5407
    ditherIds := (ditherColors asArray collect:[:clr | clr colorId]) asByteArray.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5408
888
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5409
    "/ build an index table, for fast lookup from manhatten-r-g-b distance
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5410
    "/ to the position in the colorList
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5411
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5412
    clrLookup := ByteArray new:(4096).
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5413
    index := 0.
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5414
    ditherColors keysAndValuesDo:[:clrPosition :clr |
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5415
	|r g b i|
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5416
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5417
	r := clr redByte.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5418
	g := clr greenByte.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5419
	b := clr blueByte.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5420
	i := qScramble at:((r bitShift:-4) bitAnd:16r0F) + 1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5421
	i := i + ((qScramble at:((g bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5422
	i := i + ((qScramble at:((b bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5423
	lookupPos := i.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5424
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5425
	[index < lookupPos] whileTrue:[        
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5426
	    clrLookup at:(index+1) put:(clrPosition-1-1).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5427
	    index := index + 1
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5428
	]
888
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5429
    ].
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5430
    clrLookup from:index+1 to:4096 put:(ditherColors size - 1).
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5431
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5432
"/    [index <= (4095)] whileTrue:[
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5433
"/        clrLookup at:(index+1) put:(ditherColors size - 1).
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5434
"/        index := index + 1.
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5435
"/    ].
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5436
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5437
    "/ collect ditherColor components
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5438
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5439
    lastColor := ditherColors size.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5440
    ditherIds := ByteArray uninitializedNew:lastColor.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5441
    ditherRGBBytes := ByteArray uninitializedNew:(lastColor * 3).
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5442
    index := 1.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5443
    1 to:lastColor do:[:pix |
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5444
	clr := ditherColors at:pix.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5445
	ditherRGBBytes at:index put:(clr redByte).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5446
	ditherRGBBytes at:index+1 put:(clr greenByte).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5447
	ditherRGBBytes at:index+2 put:(clr blueByte).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5448
	ditherIds at:pix put:clr colorId.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5449
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5450
	index := index + 3.
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5451
    ].
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5452
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5453
    pseudoBits := ByteArray uninitializedNew:(width * height).
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5454
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5455
    w := width + 2.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5456
    error := ByteArray uninitializedNew:w*(3*2).
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5457
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5458
    w := width.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5459
    h := height.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5460
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5461
    failed := true.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5462
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5463
%{
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5464
    int __x, __y;
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5465
    int __eR, __eG, __eB;
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5466
    unsigned char *srcP, *dstP;
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5467
    unsigned char *rgbP;
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5468
    unsigned char *idP;
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5469
    unsigned char *dp;
888
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5470
    unsigned char *__clrLookup;
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5471
    short *errP, *eP;
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5472
    int __fR, __fG, __fB;
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5473
    int iR, iG, iB;
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5474
    int idx;
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5475
    int __w = __intVal(w);
882
a3181765132b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 879
diff changeset
  5476
    int __h = __intVal(h);
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5477
    int __nColors = __intVal(lastColor);
882
a3181765132b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 879
diff changeset
  5478
    int __wR = -1, __wG, __wB;
888
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5479
    static int __qScramble[16] = {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5480
		    0x000 /* 2r000000000000    0 */,
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5481
		    0x004 /* 2r000000000100    1 */,
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5482
		    0x020 /* 2r000000100000    2 */,
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5483
		    0x024 /* 2r000000100100    3 */,
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5484
		    0x100 /* 2r000100000000    4 */,
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5485
		    0x104 /* 2r000100000100    5 */,
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5486
		    0x120 /* 2r000100100000    6 */,
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5487
		    0x124 /* 2r000100100100    7 */,
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5488
		    0x800 /* 2r100000000000    8 */,
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5489
		    0x804 /* 2r100000000100    9 */,
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5490
		    0x820 /* 2r100000100000    a */,
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5491
		    0x824 /* 2r100000100100    b */,
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5492
		    0x900 /* 2r100100000000    c */,
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5493
		    0x904 /* 2r100100000100    d */,
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5494
		    0x920 /* 2r100100100000    e */,
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5495
		    0x924 /* 2r100100100100    f */,
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5496
		  };
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5497
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5498
    if (__isByteArray(__INST(bytes))
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5499
     && __isByteArray(pseudoBits)
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5500
     && __isByteArray(rgbBytes)
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5501
     && __isByteArray(ditherRGBBytes)
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5502
     && __isByteArray(ditherIds)
888
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5503
     && __isByteArray(clrLookup)
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5504
     && __isByteArray(error)) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5505
	failed = false;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5506
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5507
	srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5508
	dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5509
	rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5510
	idP = __ByteArrayInstPtr(ditherIds)->ba_element;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5511
	__clrLookup = __ByteArrayInstPtr(clrLookup)->ba_element;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5512
	errP = (short *) _ByteArrayInstPtr(error)->ba_element;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5513
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5514
	/*
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5515
	 * clear error accumulator
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5516
	 */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5517
	eP = errP;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5518
	bzero(eP, (__w+2) * 2 * 3);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5519
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5520
	for (__y=__h; __y>0; __y--) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5521
	    __eR = __eG = __eB = 0;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5522
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5523
	    eP = &(errP[3]);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5524
	    __eR = eP[0];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5525
	    __eG = eP[1];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5526
	    __eB = eP[2];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5527
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5528
	    for (__x=__w; __x>0; __x--) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5529
		int __want;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5530
		int pix;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5531
		int __wantR, __wantG, __wantB;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5532
		int idx;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5533
		int tR, tG, tB;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5534
		int nR, nG, nB;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5535
		int dR, dG, dB;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5536
		int minDelta, bestIdx;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5537
		int cnt;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5538
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5539
		pix = *srcP++;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5540
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5541
		/*
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5542
		 * wR, wG and wB is the wanted r/g/b value;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5543
		 */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5544
		idx = pix+pix+pix;  /* pix * 3 */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5545
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5546
		__wantR = rgbP[idx] + __eR;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5547
		__wantG = rgbP[idx+1] + __eG;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5548
		__wantB = rgbP[idx+2] + __eB;
882
a3181765132b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 879
diff changeset
  5549
888
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5550
#define RED_SCALE 30
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5551
#define GREEN_SCALE 59
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5552
#define BLUE_SCALE 11
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5553
#define GOOD_DELTA 30
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5554
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5555
#define xRED_SCALE 1
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5556
#define xGREEN_SCALE 1
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5557
#define xBLUE_SCALE 1
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5558
#define xGOOD_DELTA 3
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5559
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5560
#define FAST_LOOKUP
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5561
/* #define ONE_SHOT */
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5562
#define NPROBE 8
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5563
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5564
#ifndef FAST_LOOKUP
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5565
		if ((__wantR == __wR)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5566
		 && (__wantG == __wG)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5567
		 && (__wantB == __wB)) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5568
		    /*
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5569
		     * same color again - reuse last bestMatch
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5570
		     */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5571
		} else 
888
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5572
#endif
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5573
		{
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5574
		    __wR = __wantR;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5575
		    __wG = __wantG;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5576
		    __wB = __wantB;
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5577
888
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5578
#ifdef FAST_LOOKUP
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5579
		    if(__wR > 255) __wR = 255;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5580
		    else if (__wR < 0) __wR = 0;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5581
		    if(__wG > 255) __wG = 255;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5582
		    else if (__wG < 0) __wG = 0;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5583
		    if(__wB > 255) __wB = 255;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5584
		    else if (__wB < 0) __wB = 0;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5585
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5586
		    {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5587
			int lookupIndex;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5588
			int idx, idx0;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5589
			int d, delta;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5590
			unsigned char *dp0;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5591
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5592
			dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5593
			lookupIndex =    __qScramble[((__wR & 0xF0)>>4)];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5594
			lookupIndex |=   __qScramble[((__wG & 0xF0)>>4)] >> 1;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5595
			lookupIndex |=   __qScramble[((__wB & 0xF0)>>4)] >> 2;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5596
			idx = bestIdx =__clrLookup[lookupIndex];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5597
			dp += (idx+idx+idx);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5598
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5599
			/* try color at lookupIndex */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5600
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5601
			d = dp[0];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5602
			delta = (__wR - d) * RED_SCALE;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5603
			if (delta < 0) delta = -delta;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5604
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5605
			d = dp[1];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5606
			if (__wG > d) 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5607
			    delta += (__wG - d) * GREEN_SCALE;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5608
			else 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5609
			    delta += (d - __wG) * GREEN_SCALE;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5610
			d = dp[2];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5611
			if (__wB > d) 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5612
			    delta += (__wB - d) * BLUE_SCALE;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5613
			else 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5614
			    delta += (d - __wB) * BLUE_SCALE;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5615
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5616
			if (delta <= GOOD_DELTA) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5617
			    goto foundBest;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5618
			}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5619
			minDelta = delta;
888
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5620
# ifndef ONE_SHOT
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5621
			idx0 = idx; dp0 = dp;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5622
			cnt = 0;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5623
			while ((++cnt <= NPROBE) && (idx > 0)) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5624
			    /* try previous color(s) */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5625
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5626
			    idx--; dp -= 3;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5627
			    d = dp[0];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5628
			    delta = (__wR - d) * RED_SCALE;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5629
			    if (delta < 0) delta = -delta;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5630
			    d = dp[1];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5631
			    if (__wG > d) 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5632
				delta += (__wG - d) * GREEN_SCALE;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5633
			    else 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5634
				delta += (d - __wG) * GREEN_SCALE;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5635
			    d = dp[2];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5636
			    if (__wB > d) 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5637
				delta += (__wB - d) * BLUE_SCALE;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5638
			    else 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5639
				delta += (d - __wB) * BLUE_SCALE;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5640
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5641
			    if (delta < minDelta) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5642
				bestIdx = idx;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5643
				if (delta <= GOOD_DELTA) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5644
				    goto foundBest;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5645
				}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5646
				minDelta = delta;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5647
			    }
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5648
			}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5649
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5650
			idx = idx0; dp = dp0;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5651
			cnt = 0;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5652
			while ((++cnt <= NPROBE) && (++idx < __nColors)) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5653
			    /* try next color */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5654
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5655
			    dp += 3;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5656
			    d = dp[0];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5657
			    delta = (__wR - d) * RED_SCALE;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5658
			    if (delta < 0) delta = -delta;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5659
			    d = dp[1];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5660
			    if (__wG > d) 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5661
				delta += (__wG - d) * GREEN_SCALE;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5662
			    else 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5663
				delta += (d - __wG) * GREEN_SCALE;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5664
			    d = dp[2];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5665
			    if (__wB > d) 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5666
				delta += (__wB - d) * BLUE_SCALE;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5667
			    else 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5668
				delta += (d - __wB) * BLUE_SCALE;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5669
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5670
			    if (delta < minDelta) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5671
				bestIdx = idx;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5672
				if (delta <= GOOD_DELTA) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5673
				    goto foundBest;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5674
				}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5675
				minDelta = delta;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5676
			    }
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5677
			}
888
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5678
# endif
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5679
		    }
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5680
	foundBest: ;
888
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5681
#else
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5682
/*
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5683
		    if(__wR > 255) __wR = 255;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5684
		    else if (__wR < 0) __wR = 0;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5685
		    if(__wG > 255) __wG = 255;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5686
		    else if (__wG < 0) __wG = 0;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5687
		    if(__wB > 255) __wB = 255;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5688
		    else if (__wB < 0) __wB = 0;
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5689
*/
888
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5690
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5691
		    /* find the best matching color */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5692
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5693
		    minDelta = 99999;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5694
		    bestIdx = -1;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5695
		    dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5696
		    for (idx = 0; idx<__nColors; idx++) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5697
			int d, delta;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5698
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5699
			d = dp[0];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5700
			delta = (__wR - d) * RED_SCALE;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5701
			if (delta < 0) delta = -delta;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5702
			if (delta < minDelta) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5703
			    d = dp[1];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5704
			    if (__wG > d) 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5705
				delta += (__wG - d) * GREEN_SCALE;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5706
			    else 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5707
				delta += (d - __wG) * GREEN_SCALE;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5708
			    if (delta < minDelta) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5709
				d = dp[2];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5710
				if (__wB > d) 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5711
				    delta += (__wB - d) * BLUE_SCALE;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5712
				else 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5713
				    delta += (d - __wB) * BLUE_SCALE;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5714
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5715
				if (delta < minDelta) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5716
				    bestIdx = idx;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5717
				    if (delta <= GOOD_DELTA) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5718
					break;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5719
				    }
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5720
				    minDelta = delta;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5721
				}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5722
			    }
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5723
			}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5724
			dp += 3;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5725
		    }
888
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  5726
#endif
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5727
		}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5728
		dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5729
		dp += bestIdx * 3;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5730
		dR = dp[0];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5731
		dG = dp[1];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5732
		dB = dp[2];
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5733
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5734
/*
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5735
printf("want: %d/%d/%d (%d/%d/%d) got: %d/%d/%d\n",
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5736
		__wantR, __wantG, __wantB,
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5737
		__wR, __wG, __wB,
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5738
		dR, dG, dB);
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5739
*/
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5740
		/*
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5741
		 * store the corresponding dither colors colorId
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5742
		 */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5743
		*dstP++ = idP[bestIdx];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5744
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5745
		/*
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5746
		 * the new error & distribute the error
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5747
		 */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5748
		__eR = __wantR - dR; 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5749
		if (__eR) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5750
		    tR = __eR >> 4;  /* 16th of error */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5751
		    nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5752
		    eP[0] = tR*5;         /* 5/16th for (x / y+1) */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5753
		    eP[-3] = tR*3;        /* 3/16th for (x-1 / y+1) */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5754
		    eP[3] = __eR - (tR*15);  /* 1/16th for (x+1 / y+1) */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5755
		    __eR = nR;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5756
		} else {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5757
		    __eR = eP[3];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5758
		    eP[0] = eP[-3] = eP[3] = 0;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5759
		}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5760
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5761
		__eG = __wantG - dG;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5762
		if (__eG) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5763
		    tG = __eG >> 4;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5764
		    nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5765
		    eP[1] = tG*5;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5766
		    eP[-2] = tG*3;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5767
		    eP[4] = __eG - (tG*15);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5768
		    __eG = nG;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5769
		} else {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5770
		    __eG = eP[4];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5771
		    eP[1] = eP[-2] = eP[4] = 0;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5772
		}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5773
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5774
		__eB = __wantB - dB; 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5775
		if (__eB) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5776
		    tB = __eB >> 4;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5777
		    nB = eP[5] + (tB * 7);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5778
		    eP[2] = tB*5;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5779
		    eP[-1] = tB*3;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5780
		    eP[5] = __eB - (tB*15);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5781
		    __eB = nB;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5782
		} else {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5783
		    __eB = eP[5];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5784
		    eP[2] = eP[-1] = eP[5] = 0;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5785
		}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5786
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5787
		eP += 3;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5788
	    }
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5789
	}
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5790
    }
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5791
%}.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5792
    failed ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5793
	self primitiveFailed.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5794
	^ nil
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5795
    ].
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5796
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5797
    ^ pseudoBits
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5798
!
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  5799
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5800
floydSteinbergDitheredDepth8BitsColors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue 
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5801
    "return a floyd-steinberg dithered bitmap from the receiver picture,
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5802
     which must be a depth-8 image. 
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5803
     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
  5804
     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
  5805
     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
  5806
     colors assigned to aDevice, such as the preallocated colors of the
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5807
     Color class. 
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5808
     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
  5809
     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
  5810
     for example to create dithered Depth4Images from Depth8Images."
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5811
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5812
    |pseudoBits  
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5813
     rgbBytes
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5814
     w       "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5815
     h       "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5816
     index   "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5817
     fixR    "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5818
     fixG    "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5819
     fixB    "{Class: SmallInteger }"
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  5820
     fixGfixB
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  5821
     fixIds failed map lastColor 
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  5822
     rgbIDX  "{Class: SmallInteger }"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  5823
     idxAndErrRBytes idxAndErrGBytes idxAndErrBBytes
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5824
     error clr|
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5825
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5826
    self depth ~~ 8 ifTrue:[^ nil].
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5827
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5828
    fixR := nRed.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5829
    fixR == 0 ifTrue:[ ^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5830
    fixG := nGreen.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5831
    fixG == 0 ifTrue:[ ^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5832
    fixB := nBlue.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5833
    fixB == 0 ifTrue:[ ^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5834
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5835
    "/ simple check
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5836
    (fixR * fixG * fixB) ~~ fixColors size ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5837
	self error:'invalid color array passed'.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5838
	^ nil
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5839
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5840
    fixIds := (fixColors asArray collect:[:clr | clr colorId]) asByteArray.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5841
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5842
    "/
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5843
    "/ collect color components as integer values (for integer arithmetic)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5844
    "/
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5845
    rgbBytes := ByteArray uninitializedNew:256 * 3.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5846
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5847
    index := 1.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5848
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5849
    photometric == #palette ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5850
	lastColor := colorMap size - 1
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5851
    ] ifFalse:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5852
	lastColor := 255.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5853
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5854
    0 to:lastColor do:[:pix |
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5855
	clr := self colorFromValue:pix.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5856
	rgbBytes at:index put:(clr redByte).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5857
	rgbBytes at:index+1 put:(clr greenByte).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5858
	rgbBytes at:index+2 put:(clr blueByte).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5859
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5860
	index := index + 3.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5861
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5862
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5863
    pseudoBits := ByteArray uninitializedNew:(width * height).
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5864
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5865
    w := width + 2.
1636
c30f6644666e dont use bcopy in #floydSteinbergDitheredDepth8BitsColors
Claus Gittinger <cg@exept.de>
parents: 1630
diff changeset
  5866
    error := ByteArray new:w*(3*2).
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5867
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5868
    w := width.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5869
    h := height.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5870
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  5871
    idxAndErrRBytes := ByteArray uninitializedNew:256*2.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  5872
    idxAndErrGBytes := ByteArray uninitializedNew:256*2.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  5873
    idxAndErrBBytes := ByteArray uninitializedNew:256*2.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  5874
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  5875
    fixGfixB := fixG * fixB.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  5876
    index := 1.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  5877
    0 to:255 do:[:i |
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5878
	rgbIDX := (i * (fixR-1) + 128) // 255. "red index rounded"
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5879
	idxAndErrRBytes at:index put:(rgbIDX * fixGfixB).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5880
	idxAndErrRBytes at:index+1 put:i - (rgbIDX * 255 // (fixR-1)) + 128.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5881
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5882
	rgbIDX := (i * (fixG-1) + 128) // 255. "green index rounded"
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5883
	idxAndErrGBytes at:index put:(rgbIDX * fixB). 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5884
	idxAndErrGBytes at:index+1 put:i - (rgbIDX * 255 // (fixG-1)) + 128.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5885
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5886
	rgbIDX := (i * (fixB-1) + 128) // 255. "blue index rounded"
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5887
	idxAndErrBBytes at:index put:(rgbIDX ).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5888
	idxAndErrBBytes at:index+1 put:i - (rgbIDX * 255 // (fixB-1)) + 128.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5889
	index := index + 2.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  5890
    ].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  5891
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5892
    failed := true.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5893
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5894
%{
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5895
    int __x, __y;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5896
    int __eR, __eG, __eB;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5897
    unsigned char *srcP, *dstP;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5898
    unsigned char *rgbP;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5899
    unsigned char *idP;
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  5900
    unsigned char *__idxAndErrRBytes, *__idxAndErrGBytes, *__idxAndErrBBytes;
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5901
    short *errP, *eP;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5902
    int idx;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5903
    int __w = __intVal(w);
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5904
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5905
    if (__isByteArray(__INST(bytes))
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5906
     && __isByteArray(pseudoBits)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5907
     && __isByteArray(rgbBytes)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5908
     && __isByteArray(fixIds)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5909
     && __isByteArray(error)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5910
     && __bothSmallInteger(fixR, fixG)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5911
     && __isSmallInteger(fixB)) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5912
	failed = false;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5913
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5914
	srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5915
	dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5916
	rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5917
	idP = __ByteArrayInstPtr(fixIds)->ba_element;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5918
	__idxAndErrRBytes = __ByteArrayInstPtr(idxAndErrRBytes)->ba_element;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5919
	__idxAndErrGBytes = __ByteArrayInstPtr(idxAndErrGBytes)->ba_element;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5920
	__idxAndErrBBytes = __ByteArrayInstPtr(idxAndErrBBytes)->ba_element;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5921
	errP = (short *) _ByteArrayInstPtr(error)->ba_element;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5922
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5923
	eP = errP;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5924
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5925
	for (__y=__intVal(h); __y>0; __y--) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5926
	    __eR = __eG = __eB = 0;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5927
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5928
	    eP = &(errP[3]);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5929
	    __eR = eP[0];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5930
	    __eG = eP[1];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5931
	    __eB = eP[2];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5932
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5933
	    for (__x=__w; __x>0; __x--) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5934
		int __want;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5935
		int pix;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5936
		int idx;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5937
		int tR, tG, tB;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5938
		int nR, nG, nB;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5939
		int iRGB;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5940
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5941
		pix = *srcP++;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5942
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5943
		/*
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5944
		 * wR, wG and wB is the wanted r/g/b value;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5945
		 */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5946
		pix = pix+pix+pix;  /* pix * 3 */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5947
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5948
		/*
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5949
		 * compute indexR/G/B and the new error:
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5950
		 */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5951
		__want = rgbP[pix]   + __eR;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5952
		if (__want > 255) __want = 255;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5953
		else if (__want < 0) __want = 0;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5954
		__want += __want;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5955
		idx = __idxAndErrRBytes[__want];   
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5956
		__eR = __idxAndErrRBytes[__want+1]; 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5957
		__eR -= 128;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5958
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5959
		__want = rgbP[pix+1] + __eG;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5960
		if (__want > 255) __want = 255;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5961
		else if (__want < 0) __want = 0;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5962
		__want += __want;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5963
		idx += __idxAndErrGBytes[__want];   
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5964
		__eG = __idxAndErrGBytes[__want+1]; 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5965
		__eG -= 128;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5966
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5967
		__want = rgbP[pix+2] + __eB;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5968
		if (__want > 255) __want = 255;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5969
		else if (__want < 0) __want = 0;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5970
		__want += __want;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5971
		idx += __idxAndErrBBytes[__want];   
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5972
		__eB = __idxAndErrBBytes[__want+1]; 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5973
		__eB -= 128;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5974
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5975
		/*
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5976
		 * store the corresponding dither colors colorId
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5977
		 */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5978
		*dstP++ = idP[idx];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5979
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5980
		/*
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5981
		 * distribute the error
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5982
		 */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5983
		if (__eR) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5984
		    tR = __eR >> 4;  /* 16th of error */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5985
		    nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5986
		    eP[0] = tR*5;         /* 5/16th for (x / y+1) */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5987
		    eP[-3] = tR*3;        /* 3/16th for (x-1 / y+1) */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5988
		    eP[3] = __eR - (tR*15);  /* 1/16th for (x+1 / y+1) */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5989
		    __eR = nR;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5990
		} else {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5991
		    __eR = eP[3];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5992
		    eP[0] = eP[-3] = eP[3] = 0;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5993
		}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5994
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5995
		if (__eG) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5996
		    tG = __eG >> 4;  /* 16th of error */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5997
		    nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5998
		    eP[1] = tG*5;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  5999
		    eP[-2] = tG*3;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6000
		    eP[4] = __eG - (tG*15);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6001
		    __eG = nG;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6002
		} else {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6003
		    __eG = eP[4];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6004
		    eP[1] = eP[-2] = eP[4] = 0;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6005
		}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6006
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6007
		if (__eB) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6008
		    tB = __eB >> 4;  /* 16th of error */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6009
		    nB = eP[5] + (tB * 7);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6010
		    eP[2] = tB*5;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6011
		    eP[-1] = tB*3;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6012
		    eP[5] = __eB - (tB*15);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6013
		    __eB = nB;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6014
		} else {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6015
		    __eB = eP[5];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6016
		    eP[2] = eP[-1] = eP[5] = 0;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6017
		}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6018
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6019
		eP += 3;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6020
	    }
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6021
	}
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6022
    }
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6023
%}.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6024
    failed ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6025
	self primitiveFailed.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6026
	^ nil
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6027
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6028
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6029
    ^ pseudoBits
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6030
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6031
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6032
!
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6033
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6034
floydSteinbergDitheredMonochromeBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6035
    "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
  6036
     Works for any source depths / photometric, 
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6037
     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
  6038
     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
  6039
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6040
    |dstIndex        "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6041
     nextDst         "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6042
     bytesPerMonoRow "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6043
     monoBits greyValues
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6044
     errorArray
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6045
     nextErrorArray
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6046
     e eD t
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6047
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6048
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6049
     bitCnt          "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6050
     byte            "{Class: SmallInteger }" 
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6051
     grey dT 
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6052
     eR eRB eB eLB |
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6053
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6054
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6055
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6056
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6057
    bytesPerMonoRow := (w + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6058
    monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6059
    (monoBits isNil or:[bytes isNil]) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6060
	^ nil
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6061
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6062
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6063
    errorArray := Array new:w+2.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6064
    nextErrorArray := Array new:w+2.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6065
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6066
    nextErrorArray atAllPut:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6067
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6068
    dstIndex := 1.
828
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6069
    bitCnt := 8.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6070
    byte := 0.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6071
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6072
    self depth <= 12 ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6073
	"/ fetch scaled brightness values outside of loop into a table;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6074
	"/ use table-value in loop
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6075
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6076
	greyValues := self greyMapForRange:(255 * 1024).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6077
	greyValues := greyValues collect:[:v | v isNil ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6078
						   0
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6079
					       ] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6080
						   v rounded
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6081
					       ]].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6082
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6083
	0 to:(h-1) do:[:y |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6084
	    nextDst := dstIndex + bytesPerMonoRow.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6085
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6086
	    t := errorArray.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6087
	    errorArray := nextErrorArray.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6088
	    nextErrorArray := t.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6089
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6090
	    nextErrorArray atAllPut:0.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6091
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6092
	    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
  6093
%{
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6094
		int __grey, __e;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6095
		int __byte = __intVal(byte);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6096
		OBJ *__errorArray = __ArrayInstPtr(errorArray)->a_element;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6097
		OBJ *__nextErrorArray = __ArrayInstPtr(nextErrorArray)->a_element;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6098
		int __x = __intVal(x);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6099
		int __eR, __eB, __eRB, __eLB, __eI;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6100
		int __bitCnt = __intVal(bitCnt);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6101
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6102
		__grey = __intVal(__ArrayInstPtr(greyValues)->a_element[__intVal(pixel)]);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6103
		__grey += __intVal(__errorArray[__x+1]);
828
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6104
                
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6105
		__byte <<= 1;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6106
		if (__grey > 127*1024) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6107
		    __e = __grey - (255*1024);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6108
		    __byte |= 1;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6109
		} else {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6110
		    __e = __grey;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6111
		}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6112
		if (__e) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6113
		    __eI = __e >> 4;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6114
		    __eR  = __eI * 7;            
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6115
		    __eRB = __eI * 1;            
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6116
		    __eB  = __eI * 5;            
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6117
		    __eLB = __e - __eR - __eRB - __eB;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6118
		    __errorArray[__x+2] = __MKSMALLINT(__intVal(__errorArray[__x+2]) + __eR);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6119
		    __nextErrorArray[__x+2] = __MKSMALLINT(__intVal(__nextErrorArray[__x+2]) + __eRB);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6120
		    __nextErrorArray[__x+1] = __MKSMALLINT(__intVal(__nextErrorArray[__x+1]) + __eB);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6121
		    __nextErrorArray[__x  ] = __MKSMALLINT(__intVal(__nextErrorArray[__x  ]) + __eLB);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6122
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6123
		}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6124
		__bitCnt--;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6125
		if (__bitCnt == 0) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6126
		    int __dstIndex = __intVal(dstIndex);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6127
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6128
		    __ByteArrayInstPtr(monoBits)->ba_element[__dstIndex-1] = __byte;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6129
		    dstIndex = __MKSMALLINT(__dstIndex + 1);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6130
		    __byte = 0;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6131
		    __bitCnt = 8;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6132
		}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6133
		byte = __MKSMALLINT(__byte);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6134
		bitCnt = __MKSMALLINT(__bitCnt);
828
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6135
%}.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6136
829
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  6137
"/                |eI "{ Class: SmallInteger }" 
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  6138
"/                 xE "{ Class: SmallInteger }" 
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  6139
"/                 xN "{ Class: SmallInteger }" |
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  6140
"/
828
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6141
"/                "/ get the colors grey value [0 .. 1]
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6142
"/                grey := greyValues at:(pixel + 1).
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6143
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6144
"/                "/ adjust error
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6145
"/                xE := x + 2.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6146
"/                grey := (grey + (errorArray at:xE)).
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6147
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6148
"/                byte := byte bitShift:1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6149
"/                grey > (127*1024) ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6150
"/                    byte := byte bitOr:1.      "/ white
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6151
"/                    e := grey - (255*1024)
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6152
"/                ] ifFalse:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6153
"/                    e := grey                  "/ black
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6154
"/                ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6155
"/                e ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6156
"/                    eD := e.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6157
"/                    eI := e // 16.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6158
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6159
"/                    eR  := eI * 7.              "/ 7/16 to right
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6160
"/                    eRB := eI * 1.              "/ 1/16 to right below
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6161
"/                    eB  := eI * 5.              "/ 5/16 to below
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6162
"/                    eLB := eD - eR - eRB - eB.  "/ 3/16 to left below
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6163
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6164
"/                    xN := xE + 1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6165
"/                    eR ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6166
"/                        errorArray     at:xN put:(errorArray at:xN) + eR.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6167
"/                    ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6168
"/                    eRB ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6169
"/                        nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6170
"/                    ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6171
"/                    eB ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6172
"/                        nextErrorArray at:xE put:(nextErrorArray at:xE) + eB.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6173
"/                    ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6174
"/                    eLB ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6175
"/                        xN := xE - 1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6176
"/                        nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6177
"/                    ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6178
"/                ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6179
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6180
"/                bitCnt := bitCnt - 1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6181
"/                bitCnt == 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6182
"/                    monoBits at:dstIndex put:byte.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6183
"/                    dstIndex := dstIndex + 1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6184
"/                    byte := 0.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6185
"/                    bitCnt := 8.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  6186
"/                ].
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6187
		  0
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6188
	    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6189
	    bitCnt ~~ 8 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6190
		byte := byte bitShift:bitCnt.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6191
		monoBits at:dstIndex put:byte.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6192
		bitCnt := 8.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6193
		byte := 0.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6194
	    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6195
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6196
	    dstIndex := nextDst.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6197
	].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6198
    ] ifFalse:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6199
	'Image [info]: slow floydSteinberg dither ..' infoPrintCR.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6200
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6201
	0 to:(h-1) do:[:y |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6202
	    nextDst := dstIndex + bytesPerMonoRow.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6203
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6204
	    t := errorArray.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6205
	    errorArray := nextErrorArray.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6206
	    nextErrorArray := t.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6207
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6208
	    nextErrorArray atAllPut:0.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6209
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6210
	    self colorsAtY:y from:0 to:(w-1) do:[:x :clr |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6211
		|eI "{ Class: SmallInteger }" 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6212
		 xE "{ Class: SmallInteger }" 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6213
		 xN "{ Class: SmallInteger }" |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6214
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6215
		"/ get the colors grey value [0 .. 1]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6216
		grey := (clr brightness * 255).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6217
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6218
		"/ adjust error
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6219
		xE := x + 2.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6220
		grey := (grey + (errorArray at:xE)) rounded.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6221
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6222
		byte := byte bitShift:1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6223
		grey > 127 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6224
		    byte := byte bitOr:1.      "/ white
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6225
		    e := grey - 255
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6226
		] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6227
		    e := grey                  "/ black
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6228
		].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6229
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6230
		e ~= 0 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6231
		    eD := e.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6232
		    eI := e // 16.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6233
		    eR  := eI * 7.              "/ 7/16 to right
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6234
		    eRB := eI * 1.              "/ 1/16 to right below
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6235
		    eB  := eI * 5.              "/ 5/16 to below
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6236
		    eLB := eD - eR - eRB - eB.  "/ 3/16 to left below
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6237
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6238
		    xN := xE + 1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6239
		    eR ~= 0 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6240
			errorArray     at:xN put:(errorArray at:xN) + eR.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6241
		    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6242
		    eRB ~= 0 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6243
			nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6244
		    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6245
		    eB ~= 0 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6246
			nextErrorArray at:xE put:(nextErrorArray at:xE) + eB.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6247
		    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6248
		    eLB ~= 0 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6249
			xN := xE - 1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6250
			nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6251
		    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6252
		].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6253
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6254
		bitCnt := bitCnt - 1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6255
		bitCnt == 0 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6256
		    monoBits at:dstIndex put:byte.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6257
		    dstIndex := dstIndex + 1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6258
		    byte := 0.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6259
		    bitCnt := 8.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6260
		].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6261
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6262
	    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6263
	    bitCnt ~~ 8 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6264
		byte := byte bitShift:bitCnt.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6265
		monoBits at:dstIndex put:byte.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6266
		bitCnt := 8.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6267
		byte := 0.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6268
	    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6269
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6270
	    dstIndex := nextDst.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6271
	].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6272
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6273
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6274
    ^ monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6275
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6276
    "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
  6277
    "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
  6278
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6279
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6280
nearestPaintDepth8BitsColors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue 
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6281
    "return a nearest paint bitmap from the receiver picture,
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6282
     which must be a depth-8 image. 
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6283
     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
  6284
     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
  6285
     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
  6286
     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
  6287
     Color class."
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6288
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6289
    |pseudoBits  
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6290
     fixR    "{Class: SmallInteger }"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6291
     fixG    "{Class: SmallInteger }"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6292
     fixB    "{Class: SmallInteger }"
884
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  6293
     fixGfixB 
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  6294
     r       "{Class: SmallInteger }"
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  6295
     g       "{Class: SmallInteger }"
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  6296
     b       "{Class: SmallInteger }"
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  6297
     idx     "{Class: SmallInteger }"
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  6298
     idMap lastColor 
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6299
     clr|
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6300
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6301
    self depth ~~ 8 ifTrue:[^ nil].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6302
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6303
    fixR := nRed.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6304
    fixR == 0 ifTrue:[ ^ nil].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6305
    fixG := nGreen.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6306
    fixG == 0 ifTrue:[ ^ nil].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6307
    fixB := nBlue.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6308
    fixB == 0 ifTrue:[ ^ nil].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6309
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6310
    "/ simple check
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6311
    (fixR * fixG * fixB) ~~ fixColors size ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6312
	self error:'invalid color array passed'.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6313
	^ nil
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6314
    ].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6315
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6316
    "/
884
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  6317
    "/ collect colorIds
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6318
    "/
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6319
    photometric == #palette ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6320
	lastColor := colorMap size - 1
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6321
    ] ifFalse:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6322
	lastColor := 255.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6323
    ].
884
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  6324
    fixGfixB := fixG * fixB.
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  6325
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  6326
    idMap := ByteArray uninitializedNew:256.
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  6327
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6328
    0 to:lastColor do:[:pix |
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6329
	clr := self colorFromValue:pix.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6330
	r := clr redByte.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6331
	g := clr greenByte.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6332
	b := clr blueByte.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6333
	idx := ((r * (fixR-1) + 128) // 255) * fixGfixB.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6334
	idx := idx + (((g * (fixG-1) + 128) // 255) * fixB).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6335
	idx := idx + ((b * (fixB-1) + 128) // 255).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6336
	idMap at:(pix+1) put:(fixColors at:(idx+1)) colorId.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6337
    ].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6338
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6339
    pseudoBits := ByteArray uninitializedNew:(width * height).
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6340
884
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  6341
    "/ translate
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  6342
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  6343
    bytes expandPixels:8         "xlate only"
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6344
		width:width 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6345
	       height:height
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6346
		 into:pseudoBits
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6347
	      mapping:idMap.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6348
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6349
    ^ pseudoBits
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6350
884
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  6351
    "Modified: 18.6.1996 / 09:18:09 / cg"
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6352
!
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6353
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6354
nfloydSteinbergDitheredDepth8BitsColors:colors
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6355
    "return a floyd-steinberg dithered bitmap from the receiver picture,
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6356
     which must be a depth-8 image. 
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6357
     This method expects an array of colors to be used for dithering
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6358
     (which need not be a colorCubes colors)."
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6359
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6360
    |pseudoBits  
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6361
     rgbBytes 
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6362
     ditherRGBBytes ditherColors
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6363
     w       "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6364
     h       "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6365
     index   "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6366
     numR    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6367
     numG    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6368
     numB    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6369
     bitsR    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6370
     bitsG    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6371
     bitsB    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6372
     maxBits  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6373
     maskR    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6374
     maskG    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6375
     maskB    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6376
     shR      "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6377
     shG      "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6378
     shB      "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6379
     ditherIds failed map lastColor colorsByDistance qScramble
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6380
     clrLookup lookupPos cube nCube
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6381
     dR  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6382
     dG  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6383
     dB  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6384
     iR    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6385
     iRG   "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6386
     iRGB  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6387
     clr 
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6388
     rI  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6389
     gI  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6390
     bI  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6391
     maxIDX  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6392
     subCubeColorCollection
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6393
     error 
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6394
     dl "{Class: SmallInteger }"|
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6395
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6396
    self depth ~~ 8 ifTrue:[^ nil].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6397
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6398
    "/
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6399
    "/ collect color components as integer values (for integer arithmetic)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6400
    "/
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6401
    rgbBytes := ByteArray uninitializedNew:256 * 3.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6402
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6403
    photometric == #palette ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6404
	lastColor := colorMap size - 1
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6405
    ] ifFalse:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6406
	lastColor := 255.
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6407
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6408
    index := 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6409
    0 to:lastColor do:[:pix |
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6410
	clr := self colorFromValue:pix.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6411
	rgbBytes at:index put:(clr redByte).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6412
	rgbBytes at:index+1 put:(clr greenByte).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6413
	rgbBytes at:index+2 put:(clr blueByte).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6414
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6415
	index := index + 3.
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6416
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6417
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6418
    "/ collect valid ditherColors ...
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6419
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6420
    ditherColors := colors select:[:clr | clr notNil].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6421
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6422
    "/ collect ditherColor components
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6423
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6424
    lastColor := ditherColors size.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6425
    ditherIds := ByteArray uninitializedNew:lastColor.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6426
    ditherRGBBytes := ByteArray uninitializedNew:(lastColor * 3).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6427
    index := 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6428
    1 to:lastColor do:[:pix |
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6429
	clr := ditherColors at:pix.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6430
	ditherRGBBytes at:index put:(clr redByte).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6431
	ditherRGBBytes at:index+1 put:(clr greenByte).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6432
	ditherRGBBytes at:index+2 put:(clr blueByte).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6433
	ditherIds at:pix put:clr colorId.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6434
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6435
	index := index + 3.
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6436
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6437
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6438
    "/ place the ditherColor positions into a color cube
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6439
    bitsR := 5.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6440
    bitsG := 6.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6441
    bitsB := 4.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6442
    maxBits := 6.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6443
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6444
"/    bitsR := 4.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6445
"/    bitsG := 4.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6446
"/    bitsB := 3.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6447
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6448
    numR := 1 bitShift:bitsR.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6449
    numG := 1 bitShift:bitsG.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6450
    numB := 1 bitShift:bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6451
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6452
    maskR := (numR-1) bitShift:(bitsG + bitsB).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6453
    maskG := (numG-1) bitShift:bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6454
    maskB := numB-1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6455
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6456
    shR := -16+bitsR+bitsG+bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6457
    shG := -16+bitsG+bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6458
    shB := -16+bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6459
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6460
    maxIDX := numR*numG*numB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6461
    cube := Array new:maxIDX.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6462
    1 to:lastColor do:[:clrIdx |
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6463
	clr := ditherColors at:clrIdx.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6464
	rI := clr scaledRed. rI := (rI bitShift:shR) bitAnd:maskR.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6465
	gI := clr scaledGreen. gI := (gI bitShift:shG) bitAnd:maskG.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6466
	bI := clr scaledBlue. bI := (bI bitShift:shB) bitAnd:maskB.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6467
	index := rI + gI + bI + 1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6468
	subCubeColorCollection := cube at:index.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6469
	subCubeColorCollection isNil ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6470
	    subCubeColorCollection := OrderedCollection new.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6471
	    cube at:index put:subCubeColorCollection.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6472
	].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6473
	subCubeColorCollection add:(clrIdx - 1).
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6474
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6475
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6476
    shR := 1 bitShift:(bitsG+bitsB).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6477
    shG := 1 bitShift:(bitsB).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6478
    shB := 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6479
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6480
    1 to:maxIDX do:[:i |
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6481
	subCubeColorCollection := cube at:i.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6482
	subCubeColorCollection notNil ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6483
	    cube at:i put:(subCubeColorCollection asByteArray)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6484
	]
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6485
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6486
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6487
"/    nCube := cube copy.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6488
"/
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6489
"/    cube keysAndValuesDo:[:i :indices |
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6490
"/        indices notNil ifTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6491
"/            nCube at:i put:(indices asByteArray)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6492
"/        ] ifFalse:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6493
"/            "/ find nearest color
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6494
"/        
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6495
"/            dl := 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6496
"/            [dl < maxBits] whileTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6497
"/                dR := dl negated.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6498
"/                [dR <= dl] whileTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6499
"/                    iR := i + (dR * shR).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6500
"/                    (iR > 0 and:[iR < maxIDX]) ifTrue:[    
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6501
"/                        dG := dl negated.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6502
"/                        [dG < dl] whileTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6503
"/                            iRG := iR + (dG * shG).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6504
"/                            (iRG > 0 and:[iRG < maxIDX]) ifTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6505
"/                                dB := dl negated.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6506
"/                                [dB < dl] whileTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6507
"/                                    iRGB := iRG + dB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6508
"/                                    (iRG > 0 and:[iRG < maxIDX]) ifTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6509
"/                                        (cube at:iRGB) notNil ifTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6510
"/                                            nCube at:i put:(cube at:iRGB).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6511
"/                                            dB := dG := dR := dl := 999.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6512
"/                                        ]
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6513
"/                                    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6514
"/                                    dB := dB + 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6515
"/                                ]
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6516
"/                            ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6517
"/                            dG := dG + 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6518
"/                        ]
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6519
"/                    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6520
"/                    dR := dR + 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6521
"/                ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6522
"/                dl := dl + 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6523
"/            ]
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6524
"/        ]
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6525
"/    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6526
"/self halt.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6527
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6528
    "/ now, cube contains collections of colors which are
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6529
    "/ positioned in a subCube; quickly accessed by a lookup 
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6530
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6531
    pseudoBits := ByteArray uninitializedNew:(width * height).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6532
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6533
    w := width.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6534
    h := height.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6535
    error := ByteArray new:(w+2)*3*2.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6536
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6537
%{
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6538
#define BITSR   5
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6539
#define BITSG   6
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6540
#define BITSB   4
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6541
#define MAXBITS 6
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6542
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6543
#define xBITSR   4
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6544
#define xBITSG   4
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6545
#define xBITSB   3
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6546
#define xMAXBITS 4
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6547
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6548
#define NR      32 /* (1<<BITSR) */
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6549
#define NG      64 /* (1<<BITSG) */
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6550
#define NB      16 /* (1<<BITSB) */
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6551
#define MAXRGB  64 /* (1<<MAXBITS) */
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6552
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6553
#define SHR     (BITSG+BITSB)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6554
#define SHG     BITSB
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6555
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6556
#define REMEMBER_SEARCH
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6557
#define xNO_FLOYD_STEINBERG
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6558
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6559
    int __x, __y;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6560
    int __eR, __eG, __eB;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6561
    unsigned char *srcP, *dstP;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6562
    unsigned char *rgbP;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6563
    unsigned char *idP;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6564
    unsigned char *dp;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6565
    short *errP, *eP;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6566
    int __fR, __fG, __fB;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6567
    int idx;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6568
    int __w = __intVal(w);
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6569
    int __h = __intVal(h);
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6570
    int __nColors = __intVal(lastColor);
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6571
    int __wR = -1, __wG, __wB;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6572
    OBJ *__cube;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6573
    OBJ subCubeColors;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6574
    int cubeIndex, cubeIndex2;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6575
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6576
    if (__isByteArray(__INST(bytes))
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6577
     && __isByteArray(pseudoBits)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6578
     && __isByteArray(rgbBytes)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6579
     && __isByteArray(ditherRGBBytes)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6580
     && __isByteArray(ditherIds)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6581
     && __isByteArray(error)) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6582
	failed = false;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6583
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6584
	srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6585
	dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6586
	rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6587
	idP = __ByteArrayInstPtr(ditherIds)->ba_element;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6588
	errP = (short *) __ByteArrayInstPtr(error)->ba_element;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6589
	__cube = __ArrayInstPtr(cube)->a_element;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6590
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6591
	eP = errP;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6592
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6593
	for (__y=__h; __y>0; __y--) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6594
	    eP = &(errP[3]);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6595
	    __eR = eP[0];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6596
	    __eG = eP[1];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6597
	    __eB = eP[2];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6598
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6599
	    for (__x=__w; __x>0; __x--) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6600
		int __want;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6601
		int pix;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6602
		int __wantR, __wantG, __wantB;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6603
		int idx;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6604
		int tR, tG, tB;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6605
		int nR, nG, nB;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6606
		int __dR, __dG, __dB;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6607
		int minDelta, bestIdx;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6608
		int __iR, __iG, __iB;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6609
		int cR, cG, cB;   
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6610
		int delta;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6611
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6612
		pix = *srcP++;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6613
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6614
		/*
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6615
		 * wR, wG and wB is the wanted r/g/b value;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6616
		 */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6617
		idx = pix+pix+pix;  /* pix * 3 */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6618
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6619
		__wR = __wantR = rgbP[idx] + __eR;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6620
		__wG = __wantG = rgbP[idx+1] + __eG;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6621
		__wB = __wantB = rgbP[idx+2] + __eB;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6622
		if(__wR > 255) __wR = 255;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6623
		else if (__wR < 0) __wR = 0;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6624
		if(__wG > 255) __wG = 255;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6625
		else if (__wG < 0) __wG = 0;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6626
		if(__wB > 255) __wB = 255;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6627
		else if (__wB < 0) __wB = 0;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6628
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6629
		__iR = __wR >> (8-BITSR);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6630
		__iG = __wG >> (8-BITSG);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6631
		__iB = __wB >> (8-BITSB);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6632
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6633
		cubeIndex = (__iR<<SHR) + (__iG<<SHG) + __iB;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6634
		subCubeColors = __cube[cubeIndex];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6635
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6636
		if (subCubeColors == nil) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6637
		    /* search around in spirals, for the first match */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6638
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6639
		    delta = 1;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6640
		    while (delta < MAXRGB) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6641
			/* check plane above */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6642
			cR = __iR + delta;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6643
			if ((unsigned)cR < NR) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6644
			    for (cG=__iG-delta; cG<=__iG+delta; cG++) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6645
				if ((unsigned)cG < NG) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6646
				    for (cB=__iB-delta; cB<=__iB+delta; cB++) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6647
					if ((unsigned)cB < NB) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6648
					    cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6649
					    subCubeColors = __cube[cubeIndex2];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6650
					    if (__isNonNilObject(subCubeColors)) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6651
						goto found;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6652
					    }
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6653
					}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6654
				    }
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6655
				}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6656
			    }
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6657
			}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6658
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6659
			/* check plane below */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6660
			cR = __iR - delta;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6661
			if ((unsigned)cR < NR) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6662
			    for (cG=__iG-delta; cG<=__iG+delta; cG++) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6663
				if ((unsigned)cG < NG) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6664
				    for (cB=__iB-delta; cB<=__iB+delta; cB++) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6665
					if ((unsigned)cB < NB) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6666
					    cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6667
					    subCubeColors = __cube[cubeIndex2];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6668
					    if (__isNonNilObject(subCubeColors)) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6669
						goto found;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6670
					    }
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6671
					}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6672
				    }
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6673
				}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6674
			    }
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6675
			}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6676
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6677
			/* check plane to the right */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6678
			cG = __iG + delta;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6679
			if ((unsigned)cG < NG) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6680
			    for (cR=__iR-delta+1; cR<=__iR+delta-1; cR++) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6681
				if ((unsigned)cR < NR) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6682
				    for (cB=__iB-delta; cB<=__iB+delta; cB++) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6683
					if ((unsigned)cB < NB) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6684
					    cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6685
					    subCubeColors = __cube[cubeIndex2];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6686
					    if (__isNonNilObject(subCubeColors)) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6687
						goto found;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6688
					    }
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6689
					}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6690
				    }
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6691
				}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6692
			    }
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6693
			}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6694
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6695
			/* check plane to the left */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6696
			cG = __iG - delta;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6697
			if ((unsigned)cG < NG) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6698
			    for (cR=__iR-delta+1; cR<=__iR+delta-1; cR++) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6699
				if ((unsigned)cR < NR) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6700
				    for (cB=__iB-delta; cB<=__iB+delta; cB++) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6701
					if ((unsigned)cB < NB) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6702
					    cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6703
					    subCubeColors = __cube[cubeIndex2];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6704
					    if (__isNonNilObject(subCubeColors)) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6705
						goto found;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6706
					    }
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6707
					}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6708
				    }
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6709
				}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6710
			    }
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6711
			}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6712
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6713
			/* check plane at back */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6714
			cB = __iB + delta;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6715
			if ((unsigned)cB < NB) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6716
			    for (cR=__iR-delta+1; cR<=(__iR+delta-1); cR++) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6717
				if ((unsigned)cR < NR) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6718
				    for (cG=__iG-delta+1; cG<=(__iG+delta-1); cG++) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6719
					if ((unsigned)cG < NG) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6720
					    cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6721
					    subCubeColors = __cube[cubeIndex2];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6722
					    if (__isNonNilObject(subCubeColors)) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6723
						goto found;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6724
					    }
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6725
					}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6726
				    }
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6727
				}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6728
			    }
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6729
			}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6730
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6731
			/* check plane at front */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6732
			cB = __iB - delta;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6733
			if ((unsigned)cB < NB) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6734
			    for (cR=__iR-delta+1; cR<=(__iR+delta-1); cR++) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6735
				if ((unsigned)cR < NR) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6736
				    for (cG=__iG-delta+1; cG<=(__iG+delta-1); cG++) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6737
					if ((unsigned)cG < NG) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6738
					    cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6739
					    subCubeColors = __cube[cubeIndex2];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6740
					    if (__isNonNilObject(subCubeColors)) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6741
						goto found;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6742
					    }
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6743
					}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6744
				    }
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6745
				}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6746
			    }
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6747
			}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6748
			delta = delta + 1;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6749
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6750
			if (InterruptPending) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6751
			    int d_srcP = srcP - __ByteArrayInstPtr(_INST(bytes))->ba_element;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6752
			    int d_dstP = dstP - __ByteArrayInstPtr(pseudoBits)->ba_element;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6753
			    int d_errP = errP - (short *) __ByteArrayInstPtr(error)->ba_element;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6754
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6755
			    __interrupt__();
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6756
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6757
			    srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element + d_srcP;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6758
			    dstP = __ByteArrayInstPtr(pseudoBits)->ba_element + d_dstP;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6759
			    rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6760
			    idP = __ByteArrayInstPtr(ditherIds)->ba_element;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6761
			    errP = (short *) __ByteArrayInstPtr(error)->ba_element + d_errP;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6762
			    __cube = __ArrayInstPtr(cube)->a_element;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6763
			}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6764
		    }
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6765
		    /* cannot happen - will lead to a segmentation violation ... */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6766
		    subCubeColors = nil;
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6767
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6768
    found:
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6769
		    __iR = cR;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6770
		    __iG = cG;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6771
		    __iB = cB;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6772
		    bestIdx = __ByteArrayInstPtr(subCubeColors)->ba_element[0];
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6773
#ifdef REMEMBER_SEARCH
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6774
		    __cube[cubeIndex] = __MKSMALLINT(bestIdx);
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6775
#endif
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6776
		} else {
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6777
#ifdef REMEMBER_SEARCH
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6778
		    if (__isSmallInteger(subCubeColors)) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6779
			bestIdx = __intVal(subCubeColors);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6780
		    } else 
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6781
#endif
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6782
		    {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6783
			bestIdx = __ByteArrayInstPtr(subCubeColors)->ba_element[0];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6784
		    }
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6785
		}
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6786
                
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6787
		/*
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6788
		 * ok, now, we have found a collection of nearby
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6789
		 * colors in subCubeColors.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6790
		 *
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6791
		 * since the error is at most 1/16 (i.e. roughly 6%),
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6792
		 * dont care for searching the best - simply take the
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6793
		 * first color found there.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6794
		 * (statistic reduces the error to even a smaller value).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6795
		 * There is no real problem due to that error, since
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6796
		 * it will be diffused anyway ...
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6797
		 */
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6798
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6799
#ifndef NO_FLOYD_STEINBERG
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6800
		/*
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6801
		 * fetch that colors r/g/b components
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6802
		 */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6803
		dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6804
		dp += bestIdx * 3;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6805
		__dR = dp[0];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6806
		__dG = dp[1];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6807
		__dB = dp[2];
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6808
#endif
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6809
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6810
/*
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6811
printf("want: %d/%d/%d (%d/%d/%d) got: %d/%d/%d\n",
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6812
		__wantR, __wantG, __wantB,
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6813
		__wR, __wG, __wB,
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6814
		__dR, __dG, __dB);
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6815
*/
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6816
		/*
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6817
		 * store the corresponding dither colors colorId
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6818
		 */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6819
		*dstP++ = idP[bestIdx];
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6820
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6821
#ifndef NO_FLOYD_STEINBERG
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6822
		/*
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6823
		 * the new error & distribute the error
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6824
		 */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6825
		__eR = __wantR - __dR; 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6826
		if (__eR) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6827
		    tR = __eR >> 4;  /* 16th of error */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6828
		    nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6829
		    eP[0] = tR*5;         /* 5/16th for (x / y+1) */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6830
		    eP[-3] = tR*3;        /* 3/16th for (x-1 / y+1) */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6831
		    eP[3] = __eR - (tR*15);  /* 1/16th for (x+1 / y+1) */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6832
		    __eR = nR;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6833
		} else {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6834
		    __eR = eP[3];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6835
		    eP[0] = eP[-3] = eP[3] = 0;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6836
		}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6837
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6838
		__eG = __wantG - __dG;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6839
		if (__eG) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6840
		    tG = __eG >> 4;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6841
		    nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6842
		    eP[1] = tG*5;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6843
		    eP[-2] = tG*3;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6844
		    eP[4] = __eG - (tG*15);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6845
		    __eG = nG;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6846
		} else {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6847
		    __eG = eP[4];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6848
		    eP[1] = eP[-2] = eP[4] = 0;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6849
		}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6850
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6851
		__eB = __wantB - __dB; 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6852
		if (__eB) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6853
		    tB = __eB >> 4;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6854
		    nB = eP[5] + (tB * 7);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6855
		    eP[2] = tB*5;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6856
		    eP[-1] = tB*3;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6857
		    eP[5] = __eB - (tB*15);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6858
		    __eB = nB;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6859
		} else {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6860
		    __eB = eP[5];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6861
		    eP[2] = eP[-1] = eP[5] = 0;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6862
		}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6863
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6864
		eP += 3;
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6865
#endif
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6866
	    }
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6867
	}
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6868
    }
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6869
%}.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6870
    failed ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6871
	self primitiveFailed.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6872
	^ nil
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6873
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6874
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6875
    ^ pseudoBits
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6876
!
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  6877
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  6878
orderedDitheredBitsDepth:depth
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  6879
    "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
  6880
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  6881
    ^ self
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6882
	orderedDitheredBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6883
	ditherWidth:8
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6884
	depth:depth.
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  6885
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  6886
    "Created: 15.6.1996 / 09:18:04 / cg"
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  6887
!
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  6888
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6889
orderedDitheredBitsWithDitherMatrix:ditherMatrix ditherWidth:dW depth:depth
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6890
    "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
  6891
     with a constant ditherMatrix, this can be used for thresholding.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6892
     Works for any source depths / photometric, 
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6893
     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
  6894
     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
  6895
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6896
    |f last dH nDither   
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6897
     greyLevels greyValues greyPixels greyErrors
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6898
     dstIndex        "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6899
     nextDst         
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6900
     bytesPerOutRow  "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6901
     pixelsPerByte   "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6902
     outBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6903
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6904
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6905
     bitCnt          "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6906
     byte            "{Class: SmallInteger }" |
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6907
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6908
    depth > 8 ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6909
	'IMAGE: unimplemented orderedDither conversion' errorPrintCR.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6910
	^ nil
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6911
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6912
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6913
    nDither := ditherMatrix size.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6914
    dH := nDither / dW.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6915
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6916
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6917
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6918
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6919
    greyLevels := 1 bitShift:depth.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6920
    pixelsPerByte := 8 / depth.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6921
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6922
    bytesPerOutRow := (w * depth + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6923
    outBits := ByteArray uninitializedNew:(bytesPerOutRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6924
    (outBits isNil or:[bytes isNil]) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6925
	^ nil
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6926
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6927
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6928
    dstIndex := 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6929
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6930
    self bitsPerPixel <= 12 ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6931
	"/ fetch scaled brightness values outside of loop into a table;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6932
	"/ use table-value in loop
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6933
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6934
	greyValues := self greyMapForRange:(greyLevels-1).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6935
	greyPixels := greyValues collect:[:v | v isNil ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6936
						   0
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6937
					       ] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6938
						   v truncated]].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6939
	greyPixels := ByteArray withAll:greyPixels.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6940
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6941
	greyErrors := greyValues collect:[:v | v isNil ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6942
						   0
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6943
					       ] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6944
						   ((v - v truncated) * nDither) rounded
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6945
					       ]].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6946
	greyErrors := ByteArray withAll:greyErrors.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6947
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6948
	0 to:(h-1) do:[:y |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6949
	    nextDst := dstIndex + bytesPerOutRow.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6950
	    byte := 0.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6951
	    bitCnt := 8.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6952
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6953
	    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
  6954
%{
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6955
		int __dW = __intVal(dW);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6956
		int __byte = __intVal(byte);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6957
		int __value = __intVal(value);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6958
		int __dT;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6959
		int __dstIdx;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6960
		int __pixel, __grey;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6961
		int __bitCnt = __intVal(bitCnt);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6962
		unsigned char *__greyPixels = __ByteArrayInstPtr(greyPixels)->ba_element;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6963
		unsigned char *__greyErrors = __ByteArrayInstPtr(greyErrors)->ba_element;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6964
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6965
		__pixel = __greyPixels[__value];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6966
		__grey = __greyErrors[__value];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6967
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6968
		__dT = __ByteArrayInstPtr(ditherMatrix)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6969
			    ->ba_element[__intVal(x) % __dW 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6970
					 + (__intVal(y) % __intVal(dH)) * __dW];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6971
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6972
		if (__grey > __dT) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6973
		    __pixel++;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6974
		}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6975
		__byte = (__byte << __intVal(depth)) | __pixel;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6976
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6977
		__bitCnt = __bitCnt - __intVal(depth);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6978
		if (__bitCnt == 0) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6979
		    __dstIdx = __intVal(dstIndex);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6980
		    __ByteArrayInstPtr(outBits)->ba_element[__dstIdx-1] = __byte;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6981
		    __dstIdx = __dstIdx + 1;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6982
		    dstIndex = __MKSMALLINT(__dstIdx);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6983
		    __byte = 0;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6984
		    __bitCnt = 8;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6985
		}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6986
		byte = __MKSMALLINT(__byte);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6987
		bitCnt = __MKSMALLINT(__bitCnt);
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6988
%}.
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6989
		0
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6990
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6991
	    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6992
	    bitCnt ~~ 8 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6993
		byte := byte bitShift:bitCnt.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6994
		outBits at:dstIndex put:byte.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6995
	    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6996
	    dstIndex := nextDst.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6997
	].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6998
    ] ifFalse:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  6999
	'Image [info]: slow ordered dither ..' infoPrintCR.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7000
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7001
	0 to:(h-1) do:[:y |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7002
	    nextDst := dstIndex + bytesPerOutRow.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7003
	    byte := 0.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7004
	    bitCnt := 8.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7005
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7006
	    "/ this is the representaion independent (but slow)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7007
	    "/ inner loop - it extracts colors from the receiver
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7008
            
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7009
	    self colorsAtY:y from:0 to:(w-1) do:[:x :clr |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7010
		|dstClr grey dT pixel|
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7011
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7012
		"/ get the colors grey value [0 .. 1]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7013
		grey := clr brightness.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7014
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7015
		"/ remap into [0 .. greyLevels-1]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7016
		grey := grey * (greyLevels-1).
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7017
            
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7018
		"/ get threshold pixel [0 .. greyLevels-1]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7019
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7020
		pixel := grey truncated.  
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7021
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7022
		"/ compute the error [0..1]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7023
		grey := grey - pixel.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7024
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7025
		"/ map into dither space [0 .. nDither]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7026
		grey := (grey * (nDither)) rounded.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7027
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7028
%{
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7029
		int __dW = __intVal(dW);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7030
		int __byte = __intVal(byte);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7031
		int __dT;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7032
		int __dstIdx;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7033
		int __pixel;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7034
		int __bitCnt = __intVal(bitCnt);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7035
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7036
		__dT = __ByteArrayInstPtr(ditherMatrix)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7037
			    ->ba_element[__intVal(x) % __dW 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7038
					 + (__intVal(y) % __intVal(dH)) * __dW];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7039
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7040
		__pixel = __intVal(pixel);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7041
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7042
		if (__intVal(grey) > __dT) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7043
		    __pixel++;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7044
		}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7045
		__byte = (__byte << __intVal(depth)) | __pixel;
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7046
            
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7047
		__bitCnt = __bitCnt - __intVal(depth);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7048
		if (__bitCnt == 0) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7049
		    __dstIdx = __intVal(dstIndex);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7050
		    __ByteArrayInstPtr(outBits)->ba_element[__dstIdx-1] = __byte;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7051
		    __dstIdx = __dstIdx + 1;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7052
		    dstIndex = __MKSMALLINT(__dstIdx);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7053
		    __byte = 0;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7054
		    __bitCnt = 8;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7055
		}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7056
		byte = __MKSMALLINT(__byte);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7057
		bitCnt = __MKSMALLINT(__bitCnt);
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7058
%}.
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7059
		0
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7060
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7061
	    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7062
	    bitCnt ~~ 8 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7063
		byte := byte bitShift:bitCnt.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7064
		outBits at:dstIndex put:byte.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7065
	    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7066
	    dstIndex := nextDst.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7067
	].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7068
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7069
    ^ outBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7070
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7071
831
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  7072
orderedDitheredMonochromeBits
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  7073
    "return the bitmap for a dithered monochrome bitmap from the image;
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  7074
     using a default ditherMatrix."
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  7075
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  7076
    ^ self
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7077
	orderedDitheredMonochromeBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7078
	ditherWidth:8
831
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  7079
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  7080
    "Created: 11.6.1996 / 16:48:57 / cg"
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  7081
!
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  7082
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7083
orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7084
    "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
  7085
     with a constant ditherMatrix, this can be used for thresholding.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7086
     Works for any source depths / photometric, 
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7087
     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
  7088
     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
  7089
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7090
    |f last dH nDither   
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7091
     greyValues
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7092
     dstIndex        "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7093
     nextDst         "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7094
     bytesPerMonoRow "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7095
     monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7096
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7097
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7098
     bitCnt          "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7099
     byte            "{Class: SmallInteger }" |
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7100
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7101
    nDither := ditherMatrix size.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7102
    dH := nDither / dW.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7103
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7104
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7105
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7106
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7107
    bytesPerMonoRow := (w + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7108
    monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7109
    (monoBits isNil or:[bytes isNil]) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7110
	^ nil
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7111
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7112
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7113
    dstIndex := 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7114
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7115
    self bitsPerPixel <= 12 ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7116
	"/ fetch scaled brightness values outside of loop into a table;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7117
	"/ use table-value in loop
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7118
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7119
	greyValues := self greyByteMapForRange:nDither.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7120
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7121
	0 to:(h-1) do:[:y |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7122
	    nextDst := dstIndex + bytesPerMonoRow.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7123
	    byte := 0.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7124
	    bitCnt := 8.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7125
	    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
  7126
%{
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7127
		int __dW = __intVal(dW);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7128
		int __byte = __intVal(byte);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7129
		int __dT;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7130
		int __dstIdx;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7131
		int __bitCnt = __intVal(bitCnt);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7132
		int __grey;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7133
		unsigned char *__greyValues = __ByteArrayInstPtr(greyValues)->ba_element;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7134
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7135
		__grey = __greyValues[__intVal(value)];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7136
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7137
		__dT = __ByteArrayInstPtr(ditherMatrix)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7138
			    ->ba_element[__intVal(x) % __dW 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7139
					 + (__intVal(y) % __intVal(dH)) * __dW];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7140
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7141
		__byte = __byte << 1;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7142
		if (__grey > __dT) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7143
		    __byte = __byte | 1;            /* white */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7144
		}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7145
		__bitCnt = __bitCnt - 1;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7146
		if (__bitCnt == 0) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7147
		    __dstIdx = __intVal(dstIndex);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7148
		    __ByteArrayInstPtr(monoBits)->ba_element[__dstIdx-1] = __byte;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7149
		    __dstIdx = __dstIdx + 1;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7150
		    dstIndex = __MKSMALLINT(__dstIdx);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7151
		    __byte = 0;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7152
		    __bitCnt = 8;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7153
		}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7154
		byte = __MKSMALLINT(__byte);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7155
		bitCnt = __MKSMALLINT(__bitCnt);
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7156
%}.
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7157
		0
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7158
	    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7159
	    bitCnt ~~ 8 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7160
		byte := byte bitShift:bitCnt.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7161
		monoBits at:dstIndex put:byte.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7162
	    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7163
	    dstIndex := nextDst.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7164
	].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7165
    ] ifFalse:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7166
	'Image [info]: slow ordered dither ..' infoPrintCR.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7167
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7168
	0 to:(h-1) do:[:y |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7169
	    nextDst := dstIndex + bytesPerMonoRow.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7170
	    byte := 0.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7171
	    bitCnt := 8.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7172
	    self colorsAtY:y from:0 to:(w-1) do:[:x :clr |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7173
		|dstClr grey dT|
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7174
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7175
		"/ get the colors grey value [0 .. 1]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7176
		grey := clr brightness.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7177
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7178
		"/ map into dither space [0 .. nDither]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7179
		grey := (grey * (nDither)) rounded.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7180
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7181
%{
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7182
		int __dW = __intVal(dW);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7183
		int __byte = __intVal(byte);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7184
		int __dT;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7185
		int __dstIdx;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7186
		int __bitCnt = __intVal(bitCnt);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7187
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7188
		__dT = __ByteArrayInstPtr(ditherMatrix)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7189
			    ->ba_element[__intVal(x) % __dW 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7190
					 + (__intVal(y) % __intVal(dH)) * __dW];
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7191
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7192
		__byte = __byte << 1;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7193
		if (__intVal(grey) > __dT) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7194
		    __byte = __byte | 1;            /* white */
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7195
		}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7196
		__bitCnt = __bitCnt - 1;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7197
		if (__bitCnt == 0) {
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7198
		    __dstIdx = __intVal(dstIndex);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7199
		    __ByteArrayInstPtr(monoBits)->ba_element[__dstIdx-1] = __byte;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7200
		    __dstIdx = __dstIdx + 1;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7201
		    dstIndex = __MKSMALLINT(__dstIdx);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7202
		    __byte = 0;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7203
		    __bitCnt = 8;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7204
		}
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7205
		byte = __MKSMALLINT(__byte);
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7206
		bitCnt = __MKSMALLINT(__bitCnt);
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7207
%}.
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7208
		0
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7209
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7210
"/                dT := ditherMatrix at:(x \\ dW) + (y \\ dH * dW) + 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7211
"/     
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7212
"/                byte := byte bitShift:1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7213
"/                grey < dT ifTrue:[
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7214
"/                    byte := byte bitOr:1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7215
"/                ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7216
"/                bitCnt := bitCnt - 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7217
"/                bitCnt == 0 ifTrue:[
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7218
"/                    monoBits at:dstIndex put:byte.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7219
"/                    dstIndex := dstIndex + 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7220
"/                    byte := 0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7221
"/                    bitCnt := 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7222
"/                ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7223
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7224
	    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7225
	    bitCnt ~~ 8 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7226
		byte := byte bitShift:bitCnt.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7227
		monoBits at:dstIndex put:byte.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7228
	    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7229
	    dstIndex := nextDst.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7230
	].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7231
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7232
    ^ monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7233
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7234
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7235
stevensonArceDitheredMonochromeBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7236
    "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
  7237
     Works for any source depths / photometric"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7238
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  7239
    |dstIndex        "{Class: SmallInteger }"
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7240
     nextDst         "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7241
     bytesPerMonoRow "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7242
     monoBits greyValues
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7243
     errorArray
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7244
     errorArray1 errorArray2 errorArray3
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7245
     e t
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7246
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7247
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7248
     bitCnt          "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7249
     byte            "{Class: SmallInteger }" 
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  7250
     grey
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  7251
     xE              "{Class: SmallInteger }" |
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7252
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7253
    self depth > 12 ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7254
	^ self floydSteinbergDitheredMonochromeBits
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7255
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7256
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7257
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7258
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7259
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7260
    bytesPerMonoRow := (w + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7261
    monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7262
    (monoBits isNil or:[bytes isNil]) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7263
	^ nil
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7264
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7265
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7266
    errorArray := Array new:(w+6).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7267
    errorArray1 := Array new:(w+6) withAll:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7268
    errorArray2 := Array new:(w+6) withAll:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7269
    errorArray3 := Array new:(w+6) withAll:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7270
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7271
    dstIndex := 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7272
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7273
    "/ 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
  7274
    "/ use table-value in loop
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7275
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7276
    greyValues := self greyMapForRange:(255 * 1024).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7277
    
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7278
    0 to:(h-1) do:[:y |
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7279
	nextDst := dstIndex + bytesPerMonoRow.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7280
	byte := 0.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7281
	bitCnt := 8.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7282
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7283
	t := errorArray.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7284
	errorArray := errorArray1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7285
	errorArray1 := errorArray2.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7286
	errorArray2 := errorArray3.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7287
	errorArray3 := t.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7288
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7289
	errorArray3 atAllPut:0.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7290
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7291
	self valuesAtY:y from:0 to:(w-1) do:[:x :pixel |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7292
	    |eP eD|
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7293
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7294
	    "/ get the colors grey value [0 .. 1]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7295
	    grey := greyValues at:(pixel + 1).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7296
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7297
	    "/ adjust error
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7298
	    xE := x + 3 + 1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7299
	    grey := (grey + (errorArray at:xE)).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7300
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7301
	    byte := byte bitShift:1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7302
	    grey > (127 * 1024) ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7303
		byte := byte bitOr:1.      "/ white
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7304
		e := grey - (255 * 1024)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7305
	    ] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7306
		e := grey                  "/ black
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7307
	    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7308
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7309
	    e ~= 0 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7310
		"/ distribute the error:
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7311
		"/                  XX    32
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7312
		"/         12    26    30    16
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7313
		"/            12    26    12
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7314
		"/          5    12    12     5
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7315
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7316
		eD := e.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7317
		e := e // 200.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7318
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7319
		eP := e * 32. eD := eD - eP.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7320
		errorArray at:xE+2 put:(errorArray at:xE+2) + eP.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7321
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7322
		eP := e * 30. eD := eD - eP.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7323
		errorArray1 at:xE+1 put:(errorArray1 at:xE+1) + eP.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7324
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7325
		eP := e * 16. eD := eD - eP.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7326
		errorArray1 at:xE+3 put:(errorArray1 at:xE+3) + eP.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7327
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7328
		eP := e * 26. eD := eD - eP.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7329
		errorArray1 at:xE-1 put:(errorArray1 at:xE-1) + eP.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7330
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7331
		eD := eD - eP.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7332
		errorArray2 at:xE put:(errorArray2 at:xE) + eP.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7333
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7334
		eP := e * 12. eD := eD - eP.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7335
		errorArray1 at:xE-3 put:(errorArray1 at:xE-3) + eP.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7336
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7337
		eD := eD - eP.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7338
		errorArray2 at:xE-2 put:(errorArray2 at:xE-2) + eP.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7339
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7340
		eD := eD - eP.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7341
		errorArray2 at:xE+2 put:(errorArray2 at:xE+2) + eP.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7342
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7343
		eD := eD - eP.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7344
		errorArray3 at:xE-1 put:(errorArray3 at:xE-1) + eP.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7345
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7346
		eD := eD - eP.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7347
		errorArray3 at:xE+1 put:(errorArray3 at:xE+1) + eP.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7348
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7349
		eP := e * 5. eD := eD - eP.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7350
		errorArray3 at:xE-3 put:(errorArray3 at:xE-3) + eP.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7351
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7352
		eP := eD.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7353
		errorArray3 at:xE+3 put:(errorArray3 at:xE+3) + eP.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7354
	    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7355
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7356
	    bitCnt := bitCnt - 1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7357
	    bitCnt == 0 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7358
		monoBits at:dstIndex put:byte.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7359
		dstIndex := dstIndex + 1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7360
		byte := 0.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7361
		bitCnt := 8.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7362
	    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7363
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7364
	].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7365
	bitCnt ~~ 8 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7366
	    byte := byte bitShift:bitCnt.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7367
	    monoBits at:dstIndex put:byte.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7368
	].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7369
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7370
	dstIndex := nextDst.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7371
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7372
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7373
    ^ monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7374
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7375
    "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
  7376
    "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
  7377
! !
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7378
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  7379
!Image methodsFor:'drawing'!
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  7380
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  7381
fillRectangleX:x y:y width:w height:h with:aColor
1630
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  7382
    "fill a rectangular area with a color"
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  7383
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  7384
    |pixel|
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  7385
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  7386
    pixel := self valueFromColor:aColor.
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  7387
    self fillRectangleX:x y:y width:w height:h withValue:pixel
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  7388
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  7389
    "Modified: 22.4.1997 / 14:02:50 / cg"
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  7390
!
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  7391
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  7392
fillRectangleX:x y:y width:w height:h withValue:aPixelValue
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  7393
    "fill a rectangular area with some pixel value.
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  7394
     May be redefined in concrete subclasses for more performance, if req'd."
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  7395
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  7396
    |xI "{ Class: SmallInteger }"
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  7397
     yI "{ Class: SmallInteger }"
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  7398
     wI "{ Class: SmallInteger }" 
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  7399
     hI "{ Class: SmallInteger }"|
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  7400
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  7401
    xI := x.
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  7402
    yI := y.
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  7403
    wI := w.
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  7404
    hI := h.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7405
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  7406
    yI to:yI+hI-1 do:[:yRun |
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7407
        xI to:xI+wI-1 do:[:xRun |
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7408
            self pixelAtX:xRun y:yRun put:aPixelValue
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7409
        ]
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  7410
    ]
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  7411
1630
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  7412
    "Created: 22.4.1997 / 14:02:14 / cg"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7413
    "Modified: 24.4.1997 / 17:24:58 / cg"
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  7414
! !
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  7415
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7416
!Image methodsFor:'enumerating'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7417
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7418
atY:y from:x1 to:x2 do:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7419
    "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
  7420
     The block is passed the color at each pixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7421
     The code here provides a generic and slow implementation, and
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7422
     should be redefined in concrete subclasses, to avoid some processing
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7423
     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
  7424
     and also the color allocation)."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7425
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  7426
    self obsoleteMethodWarning:'use #colorsAtY:from:to:do:'.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  7427
    self colorsAtY:y from:x1 to:x2 do:aBlock
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  7428
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  7429
    "Modified: 7.6.1996 / 19:13:30 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  7430
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  7431
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  7432
colorsAtY:y from:x1 to:x2 do:aBlock
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  7433
    "perform aBlock for each pixel from x1 to x2 in row y.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  7434
     The block is passed the color at each pixel.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  7435
     The code here provides a generic and slow implementation, and
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  7436
     should be redefined in concrete subclasses, to avoid some processing
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  7437
     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
  7438
     and also the color allocation)."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  7439
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7440
    |xStart "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7441
     xEnd   "{Class: SmallInteger }"|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7442
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7443
    xStart := x1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7444
    xEnd := x2.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7445
    xStart to:xEnd do:[:xRun |
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7446
	aBlock value:xRun value:(self atX:xRun y:y)
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7447
    ]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  7448
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  7449
    "Created: 7.6.1996 / 19:12:51 / cg"
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7450
    "Modified: 10.6.1996 / 10:27:29 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7451
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7452
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7453
colorsFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7454
    "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
  7455
     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
  7456
     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
  7457
     The code here provides a generic and slow implementation, and
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7458
     should be redefined in concrete subclasses, to avoid some processing
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7459
     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
  7460
     and especially, the color allocations)."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7461
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  7462
    |yS "{Class: SmallInteger }"
942
5e45da3c19d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
  7463
     yE "{Class: SmallInteger }"
5e45da3c19d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
  7464
     yR|
5e45da3c19d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
  7465
5e45da3c19d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
  7466
    yS := yStart.
5e45da3c19d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
  7467
    yE := yEnd.
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  7468
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  7469
    yS to:yE do:[:yRun |    
942
5e45da3c19d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
  7470
	yR := yRun.
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7471
	self colorsAtY:yRun from:xStart to:xEnd do:[:xRun :color |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7472
	    aBlock value:xRun value:yR value:color 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7473
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7474
    ]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  7475
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  7476
    "Modified: 11.7.1996 / 19:50:47 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7477
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7478
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7479
valueAtY:y from:x1 to:x2 do:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7480
    "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
  7481
     Obsolete - remains for backward compatibility."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  7482
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  7483
    self obsoleteMethodWarning:'use #valuesAtY:from:to:do:'.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  7484
    self valuesAtY:y from:x1 to:x2 do:aBlock
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  7485
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  7486
    "Modified: 7.6.1996 / 19:11:06 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  7487
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  7488
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  7489
valuesAtY:y from:x1 to:x2 do:aBlock
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7490
    "WARNING: for now, this enumerates pixel values 
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7491
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7492
     In the future, this will enumerate colors 
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7493
     Use #pixelAtT:from:to:do: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7494
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7495
     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
  7496
     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
  7497
     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
  7498
     (see also Image>>atY:from:to:do:).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7499
     The code here provides a generic and slow implementation, and
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7500
     should be redefined in concrete subclasses, to avoid some processing
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7501
     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
  7502
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7503
    |xStart "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7504
     xEnd   "{Class: SmallInteger }"|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7505
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7506
    xStart := x1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7507
    xEnd := x2.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7508
    xStart to:xEnd do:[:xRun |
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7509
        aBlock value:xRun value:(self pixelAtX:xRun y:y)
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7510
    ]
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  7511
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  7512
    "Created: 7.6.1996 / 19:09:51 / cg"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7513
    "Modified: 24.4.1997 / 16:55:38 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7514
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7515
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7516
valuesFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7517
    "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
  7518
     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
  7519
     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
  7520
     The code here provides a generic and slow implementation, and
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7521
     should be redefined in concrete subclasses, to avoid some processing
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7522
     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
  7523
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7524
    |xS "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7525
     xE "{Class: SmallInteger }"|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7526
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7527
    xS := xStart.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7528
    xE := xEnd.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7529
    yStart to:yEnd do:[:yRun |    
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7530
	self valuesAtY:yRun from:xStart to:xEnd do:[:xRun :pixel |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7531
	    aBlock value:xRun value:yRun value:pixel
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7532
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7533
    ]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  7534
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  7535
    "Modified: 7.6.1996 / 19:09:29 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  7536
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
  7537
48194c26a46c Initial revision
claus
parents:
diff changeset
  7538
!Image methodsFor:'image manipulations'!
48194c26a46c Initial revision
claus
parents:
diff changeset
  7539
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
  7540
applyPixelValuesTo:pixelFunctionBlock into:newImage
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
  7541
    "helper for withPixelFunctionAppliedToValues:
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
  7542
     enumerate pixelValues and evaluate the block for each.
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
  7543
     To be redefined by subclasses for better performance."
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
  7544
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
  7545
    |w  "{Class: SmallInteger }"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7546
     h  "{Class: SmallInteger }"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7547
     newPixel newPixelRow pixelRow|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7548
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7549
    w := width.
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
  7550
    h := height - 1.
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
  7551
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7552
    newPixelRow := Array new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7553
    pixelRow := self pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7554
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
  7555
    0 to:h do:[:y |
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7556
        self rowAt:y into:pixelRow.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7557
        1 to:w do:[:col |
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7558
            newPixel := pixelFunctionBlock
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7559
                            value:self
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7560
                            value:(pixelRow at:col)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7561
                            value:(col-1)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7562
                            value:y.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7563
            newPixelRow at:col put:newPixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7564
        ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7565
        newImage rowAt:y putAll:newPixelRow
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7566
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7567
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7568
    "Modified: 24.4.1997 / 16:18:31 / cg"
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
  7569
!
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
  7570
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7571
colorMapProcessing:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7572
    "a helper for all kinds of colormap manipulations.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  7573
     The argument, aBlock is called for every colormap entry, 
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  7574
     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
  7575
     This will fail for non-palette images.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  7576
     See examples in Image>>copyWithColorMapProcessing:"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7577
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7578
    |nColors "{ Class: SmallInteger }"|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7579
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7580
    colorMap isNil ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7581
	^ self error:'image has no colormap'
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7582
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7583
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7584
    nColors := colorMap size.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7585
    1 to:nColors do:[:index |
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7586
	|clr|
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7587
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7588
	clr := colorMap at:index.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7589
	clr notNil ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7590
	    colorMap at:index put:(aBlock value:clr)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7591
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7592
    ]
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  7593
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  7594
    "Modified: 23.4.1996 / 11:13:55 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7595
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7596
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  7597
copyWithColorMapProcessing:aBlock
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  7598
    "a helper to create & return new images based on the receiver with
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  7599
     some colorMap processing. The receiver is copied, and the copied images
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  7600
     colormap is modified by replacing entries with the result of the processing block,
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  7601
     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
  7602
     a color.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7603
     CAVEAT: this only works with palette images (i.e. not for rgb or greyScale)"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  7604
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  7605
    |newImage|
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  7606
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  7607
    newImage := self copy.
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  7608
    newImage colorMap isNil ifTrue:[
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7609
        self error:'no colormap in image'.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7610
        ^ nil
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  7611
    ].
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  7612
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  7613
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  7614
     the code below manipulates the colormap.
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  7615
     For non-palette images, special code is required
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  7616
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  7617
    newImage colorMapProcessing:aBlock.
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  7618
    ^ newImage
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  7619
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  7620
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  7621
     leave red component only:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  7622
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7623
     (Image fromFile:'bitmaps/gifImages/claus.gif') 
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7624
        copyWithColorMapProcessing:[:clr | Color red:(clr red) green:0 blue:0] 
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  7625
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  7626
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  7627
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  7628
     make it reddish:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  7629
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7630
     (Image fromFile:'bitmaps/gifImages/claus.gif') 
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7631
        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
  7632
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  7633
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  7634
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  7635
     invert:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  7636
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7637
     (Image fromFile:'bitmaps/gifImages/claus.gif') 
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7638
        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
  7639
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  7640
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  7641
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  7642
     lighter:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  7643
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7644
     (Image fromFile:'bitmaps/gifImages/claus.gif') 
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7645
        copyWithColorMapProcessing:[:clr | |r g b|
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7646
                                                r := clr red.  g := clr green.  b := clr blue.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7647
                                                Color red:(r + (100-r//2)) 
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7648
                                                      green:(g + (100-g//2)) 
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7649
                                                      blue:(b + (100-b//2))]
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  7650
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  7651
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  7652
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  7653
     darker:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  7654
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7655
     (Image fromFile:'bitmaps/gifImages/claus.gif') 
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7656
        copyWithColorMapProcessing:[:clr | Color red:(clr red//2) green:(clr green // 2) blue:(clr blue // 2)] 
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7657
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7658
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7659
    "Modified: 24.4.1997 / 18:28:05 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  7660
!
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  7661
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7662
darkened
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7663
    "return a new image which is slightly darker than the receiver.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7664
     The receiver must be a palette image (currently).
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7665
     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
  7666
     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
  7667
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7668
     ^ self 
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7669
        copyWithColorMapProcessing:[:clr | clr darkened]
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7670
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7671
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7672
     (Image fromFile:'bitmaps/gifImages/claus.gif') inspect
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7673
     (Image fromFile:'bitmaps/gifImages/claus.gif') darkened inspect
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7674
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7675
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7676
    "Modified: 24.4.1997 / 18:28:31 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7677
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7678
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  7679
easyRotateBitsInto:destinationImage angle:degrees
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  7680
    "helper for rotation - does the actual pixel shuffling.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  7681
     by degrees clockwise. Here, only 90, 180 and 270 degrees
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  7682
     are implemented. Hard angles are done in #hardRotate:.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  7683
     The code here is depth-independent (but not too fast);
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  7684
     can be redefined in subclasses for more performance"
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  7685
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  7686
    |w  "{Class: SmallInteger }"
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  7687
     h  "{Class: SmallInteger }"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7688
     c2 r2 pixelArray|
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  7689
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  7690
    w := width - 1.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  7691
    h := height - 1.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  7692
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7693
    pixelArray := self pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7694
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  7695
    degrees = 90 ifTrue:[
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  7696
        0 to:h do:[:row |
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7697
            self rowAt:row into:pixelArray startingAt:1.
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  7698
            c2 := h-row.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7699
            0 to:w do:[:col |
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7700
                destinationImage pixelAtX:c2 y:col put:(pixelArray at:(col+1)).
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  7701
            ]
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  7702
        ].
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  7703
        ^ self.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  7704
    ].
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  7705
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  7706
    degrees = 180 ifTrue:[
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  7707
        0 to:h do:[:row |
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7708
            self rowAt:row into:pixelArray startingAt:1.
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  7709
            r2 := h - row.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7710
            0 to:w do:[:col |
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7711
                destinationImage pixelAtX:(w-col) y:r2 put:(pixelArray at:(col+1)).
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  7712
            ]
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  7713
        ].
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  7714
        ^ self
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  7715
    ].
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  7716
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  7717
    "/ degrees = 270
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  7718
    0 to:h do:[:row |
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7719
        self rowAt:row into:pixelArray startingAt:1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7720
        0 to:w do:[:col |
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7721
            destinationImage pixelAtX:row y:(w-col) put:(pixelArray at:(col+1)).
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  7722
        ]
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  7723
    ]
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  7724
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  7725
    "Created: 23.4.1997 / 14:36:45 / cg"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7726
    "Modified: 24.4.1997 / 17:26:26 / cg"
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  7727
!
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  7728
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7729
flipHorizontal
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7730
    "destructively inplace horizontal flip"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7731
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7732
    |h  "{Class: SmallInteger }"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7733
     pixelArray|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7734
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7735
    h := height - 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7736
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7737
    pixelArray := self pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7738
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7739
    0 to:h do:[:row |
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7740
        self rowAt:row into:pixelArray.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7741
        pixelArray reverse.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7742
        self rowAt:row putAll:pixelArray.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7743
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7744
1386
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  7745
    mask notNil ifTrue:[
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7746
        mask flipHorizontal
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7747
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7748
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7749
    "/ flush device info
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7750
    self restored
1386
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  7751
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7752
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7753
     (Image fromFile:'bitmaps/gifImages/garfield.gif') flipHorizontal inspect
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7754
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7755
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7756
    "Modified: 24.4.1997 / 18:29:13 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7757
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7758
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7759
flipVertical
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7760
    "inplace vertical flip"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7761
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7762
    |h           "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7763
     bytesPerRow "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7764
     buffer 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7765
     indexLow    "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7766
     indexHi     "{Class: SmallInteger }"|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7767
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7768
    bytesPerRow := self bytesPerRow.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7769
    buffer := ByteArray new:bytesPerRow.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7770
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7771
    h := height - 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7772
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7773
    indexLow := 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7774
    indexHi := bytesPerRow * h + 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7775
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7776
    0 to:(h // 2) do:[:row |
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7777
        buffer replaceFrom:1 to:bytesPerRow with:bytes startingAt:indexLow.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7778
        bytes replaceFrom:indexLow to:(indexLow + bytesPerRow - 1) with:bytes startingAt:indexHi.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7779
        bytes replaceFrom:indexHi to:(indexHi + bytesPerRow - 1) with:buffer startingAt:1.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7780
        indexLow := indexLow + bytesPerRow.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7781
        indexHi := indexHi - bytesPerRow.
1386
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  7782
    ].
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  7783
    mask notNil ifTrue:[
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7784
        mask flipVertical
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7785
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7786
    "flush device info"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7787
    self restored
1386
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  7788
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7789
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7790
     (Image fromFile:'bitmaps/gifImages/garfield.gif') flipVertical inspect
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7791
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7792
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7793
    "Modified: 24.4.1997 / 18:29:36 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7794
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7795
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7796
hardMagnifiedBy:scalePoint
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7797
    "return a new image magnified by scalePoint, aPoint.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7798
     This is the general magnification method, handling non-integral values.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7799
     It is slower than the integral magnification method."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7800
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7801
    |mX        
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7802
     mY        
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7803
     newWidth  "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7804
     newHeight "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7805
     w         "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7806
     h         "{ Class: SmallInteger }"
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  7807
     newImage newBits bitsPerPixel newBytesPerRow newMask
888
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  7808
     value 
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7809
     srcRow pixelArray|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7810
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7811
    mX := scalePoint x.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7812
    mY := scalePoint y.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7813
    ((mX < 0) or:[mY < 0]) ifTrue:[^ nil].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7814
    ((mX = 1) and:[mY = 1]) ifTrue:[^ self].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7815
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7816
    newWidth := (width * mX) truncated.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7817
    newHeight := (height * mY) truncated.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7818
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7819
    bitsPerPixel := self depth.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7820
    newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7821
    newBits := ByteArray uninitializedNew:(newBytesPerRow * newHeight).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7822
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  7823
    mask notNil ifTrue:[
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7824
        newMask := (mask magnifiedBy:scalePoint)
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  7825
    ].
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  7826
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7827
    newImage := self species new.
888
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  7828
    newImage 
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7829
        width:newWidth 
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7830
        height:newHeight 
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7831
        photometric:photometric 
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7832
        samplesPerPixel:samplesPerPixel 
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7833
        bitsPerSample:bitsPerSample 
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7834
        colorMap:colorMap copy
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7835
        bits:newBits
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7836
        mask:newMask.
905
228d503775d9 everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents: 904
diff changeset
  7837
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7838
    "walk over destination image fetching pixels from source image"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7839
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7840
    w := newWidth - 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7841
    h := newHeight - 1.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7842
    pixelArray := newImage pixelArraySpecies new:newWidth.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7843
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7844
    0 to:h do:[:row |
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7845
        srcRow := (row // mY).
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7846
        0 to:w do:[:col |
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7847
            value := self pixelAtX:(col // mX) y:srcRow.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7848
            pixelArray at:(col+1) put:value.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7849
        ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7850
        newImage rowAt:row putAll:pixelArray.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7851
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7852
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7853
    ^ newImage
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7854
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7855
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7856
     |i|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7857
     i := Image fromFile:'bitmaps/gifImages/claus.gif'.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  7858
     Time millisecondsToRun:[
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7859
         i := i hardMagnifiedBy:0.5@0.5
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7860
     ].
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7861
     i
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7862
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7863
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  7864
    "Modified: 24.4.1997 / 18:30:24 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7865
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7866
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7867
hardRotated:degrees
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7868
    "return a new image from the old one, by rotating the image
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7869
     degrees clockwise. 
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7870
     Warning: the returned image will be larger than the original image."
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7871
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7872
    |p r a aN p1 p2 p3 p4 maxX minX maxY minY
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7873
     newImage 
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7874
     newWidth  "{ Class: SmallInteger }"
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7875
     newHeight "{ Class: SmallInteger }"
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7876
     newBytesPerRow newBits
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7877
     blackPixel halfW halfH radians m t bad
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7878
     bytesPerRow myDepth maskBits
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7879
     pX pY srcX srcY pix nX nY 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7880
     sinRot cosRot sinPY cosPY|
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  7881
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7882
    "/ placing the image at the origin,
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7883
    "/ compute the diagonal and angle.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7884
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7885
    p := (width - 1 / 2) @ (height - 1 / 2).
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7886
    r := p r.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7887
    a := p angle.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7888
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7889
    "/ add the rotation 
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7890
    "/ (sight - subtract, we defined things clockwise ... 
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7891
    "/  ... in contrast to point which thinks counter-clockwise)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7892
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7893
    aN := a - degrees.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7894
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7895
    "/ compute new corner points
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7896
    p1 := Point r:r angle:aN.         "/ rotated topRight
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7897
    p2 := Point r:r angle:aN-a-a.     "/ rotated bottomRight
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7898
    p3 := p1 * -1.                    "/ rotated bottomLeft
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7899
    p4 := p2 * -1.                    "/ rotated topLeft
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7900
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7901
    "/ compute the boundary of the new image
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7902
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7903
    maxX := minX := p1 x.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7904
    (t := p2 x) > maxX ifTrue:[
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  7905
        maxX := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7906
    ] ifFalse:[
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  7907
        t < minX ifTrue:[minX := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7908
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7909
    (t := p3 x) > maxX ifTrue:[
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  7910
        maxX := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7911
    ] ifFalse:[
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  7912
        t < minX ifTrue:[minX := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7913
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7914
    (t := p4 x) > maxX ifTrue:[
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  7915
        maxX := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7916
    ] ifFalse:[
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  7917
        t < minX ifTrue:[minX := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7918
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7919
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7920
    maxY := minY := p1 y.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7921
    (t := p2 y) > maxY ifTrue:[
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  7922
        maxY := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7923
    ] ifFalse:[
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  7924
        t < minY ifTrue:[minY := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7925
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7926
    (t := p3 y) > maxY ifTrue:[
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  7927
        maxY := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7928
    ] ifFalse:[
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  7929
        t < minY ifTrue:[minY := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7930
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7931
    (t := p4 y) > maxY ifTrue:[
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  7932
        maxY := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7933
    ] ifFalse:[
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  7934
        t < minY ifTrue:[minY := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7935
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7936
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7937
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7938
    newWidth := (maxX - minX) rounded + 1.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7939
    newHeight := (maxY - minY) rounded + 1.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7940
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7941
    newImage := self species new.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7942
    newImage width:newWidth.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7943
    newImage height:newHeight.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7944
    newBytesPerRow := newImage bytesPerRow.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7945
    newBits := ByteArray uninitializedNew:(newBytesPerRow * newHeight).
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7946
    newImage bits:newBits.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7947
    newImage photometric:photometric.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7948
    newImage samplesPerPixel:samplesPerPixel.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7949
    newImage bitsPerSample:bitsPerSample.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7950
    newImage colorMap:colorMap copy.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7951
    newImage maskedPixelsAre0:maskedPixelsAre0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7952
    mask notNil ifTrue:[
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  7953
        newImage mask:(mask rotated:degrees)
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7954
    ] ifFalse:[
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  7955
        self isMask ifFalse:[
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  7956
            self depth ~~ 1 ifTrue:[
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  7957
                m := ImageMask width:width height:height.
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  7958
                m bits:(maskBits := ByteArray new:(m bytesPerRow * height)).
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  7959
                maskBits atAllPut:16rFF.
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  7960
                newImage mask:(m rotated:degrees)
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  7961
            ]
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  7962
        ]
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7963
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7964
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7965
    maskedPixelsAre0 ifTrue:[
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  7966
        blackPixel := 0.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7967
    ] ifFalse:[
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  7968
        blackPixel := self valueFromColor:Color black.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  7969
        blackPixel isNil ifTrue:[
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  7970
            blackPixel := self valueFromColor:Color white.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  7971
            blackPixel isNil ifTrue:[
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  7972
                blackPixel := 0.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  7973
            ]
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  7974
        ]
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7975
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7976
    self isMask ifTrue:[
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  7977
        blackPixel := 0.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7978
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7979
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7980
    myDepth := self depth.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7981
    newBits atAllPut:0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7982
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7983
    "/ now, walk over destination pixels,
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  7984
    "/ fetching from source. 
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  7985
    "/ (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
  7986
    "/  in the destination image ...)
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7987
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7988
    halfW := (width - 1) / 2.0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7989
    halfH := (height - 1) / 2.0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7990
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7991
    radians := degrees degreesToRadians.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7992
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7993
    bytesPerRow := self bytesPerRow.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7994
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7995
%{
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7996
    int __newHeight = __intVal(newHeight);
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7997
    int __newWidth = __intVal(newWidth);
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7998
    int __height = __intVal(__INST(height));
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  7999
    int __width = __intVal(__INST(width));
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8000
    double __minX, __minY, __radians;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8001
    double __halfW, __halfH;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8002
    int __dstX, __dstY;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8003
    int __depth = __intVal(myDepth);
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8004
    unsigned char *__srcBytes, *__dstBytes;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8005
    unsigned char *__dstPtr, *__dstRowPtr, *__dstEndPtr;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8006
    int __nSrcBytes, __nDstBytes;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8007
    int __srcBytesPerRow = __intVal(bytesPerRow);
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8008
    int __dstBytesPerRow = __intVal(newBytesPerRow);
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  8009
    int __dstMask, __blackPixel;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  8010
    double __sin, __cos;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  8011
    double sin(), cos();
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8012
#   define Float_PI 3.14159
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8013
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8014
    bad = true;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8015
    if (1
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8016
     && __isFloat(minX) 
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8017
     && __isFloat(minY)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8018
     && __isFloat(radians)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8019
     && __isFloat(halfW)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8020
     && __isFloat(halfH)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8021
     && __isByteArray(newBits)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8022
     && __isByteArray(__INST(bytes))) {
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8023
        __srcBytes = __ByteArrayInstPtr(__INST(bytes))->ba_element;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8024
        __dstBytes = __ByteArrayInstPtr(newBits)->ba_element;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8025
        __nSrcBytes = __byteArraySize(__INST(bytes));
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8026
        __nDstBytes = __byteArraySize(newBits);
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8027
        __blackPixel = __intVal(blackPixel);
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8028
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8029
        __radians = __floatVal(radians);
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8030
        __radians = -__radians; /* sigh: clock-wise */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8031
        __sin = sin(__radians);
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8032
        __cos = cos(__radians);
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8033
        __minX = __floatVal(minX);
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8034
        __minY = __floatVal(minY);
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8035
        __halfW = __floatVal(halfW);
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8036
        __halfH = __floatVal(halfH);
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8037
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8038
        __dstRowPtr = __dstBytes;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8039
        __dstEndPtr = __dstBytes + __nDstBytes;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  8040
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  8041
#       define EARLY_OUT
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8042
#       define FAST_ADVANCE 5
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8043
#       define FAST_ADVANCE2
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8044
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8045
        switch (__depth) {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8046
            case 8:
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8047
                for (__dstY = 0; __dstY < __newHeight; __dstY++) {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8048
                    double __pY, __sinPY, __cosPY;
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
  8049
#ifdef EARLY_OUT
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8050
                    int didFetchInRow = 0;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  8051
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8052
                    __pY = (double)(__dstY + __minY);
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8053
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8054
                    __sinPY = __sin * __pY;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8055
                    __cosPY = __cos * __pY;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8056
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8057
                    __dstPtr = __dstRowPtr;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8058
                    __dstRowPtr += __dstBytesPerRow;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8059
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8060
                    for (__dstX = 0; __dstX < __newWidth; __dstX++) {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8061
                        double __pX, __nX;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8062
                        unsigned __pix;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8063
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8064
                        /* translate X in destination (center to 0/0) */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8065
                        __pX = (double)(__dstX + __minX);
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8066
                        /* rotate X */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8067
                        __nX = (__cos * __pX) - __sinPY;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8068
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8069
                        /* translate X in source (origin to 0/0) */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8070
                        __nX = __nX + __halfW + 0.5;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8071
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8072
                        /* inside ? */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8073
                        if (__nX < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  8074
#ifdef EARLY_OUT
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8075
                            if (didFetchInRow) {
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8076
                                break;
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8077
                            }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  8078
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8079
#ifdef FAST_ADVANCE
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8080
                            if (__blackPixel == 0) {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8081
                                do {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8082
                                    /* try advance by FAST_ADVANCE pixels ... */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8083
                                    __dstX += FAST_ADVANCE; __dstPtr += FAST_ADVANCE;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8084
                                    if (__dstX >= __newWidth) {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8085
                                        break;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8086
                                    }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8087
                                    __pX = (double)(__dstX + __minX);
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8088
                                    __nX = (__cos * __pX) - __sinPY;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8089
                                    __nX = __nX + __halfW + 0.5;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8090
                                } while (__nX < 0);
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8091
                                __dstX -= FAST_ADVANCE; __dstPtr -= FAST_ADVANCE;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8092
                            }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8093
#endif
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8094
                            __pix = __blackPixel;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8095
                        } else {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8096
                            int __srcX;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8097
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8098
                            __srcX = (int)__nX;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8099
                            /* inside ? */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8100
                            if (__srcX >= __width) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  8101
#ifdef EARLY_OUT
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8102
                                if (didFetchInRow) {
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8103
                                    break;
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8104
                                }
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
  8105
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8106
#ifdef FAST_ADVANCE2
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8107
                                if (__blackPixel == 0) {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8108
                                    do {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8109
                                        /* try advance by FAST_ADVANCE pixels ... */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8110
                                        __dstX += FAST_ADVANCE; __dstPtr += FAST_ADVANCE;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8111
                                        if (__dstX >= __newWidth) {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8112
                                            break;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8113
                                        }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8114
                                        __pX = (double)(__dstX + __minX);
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8115
                                        __nX = (__cos * __pX) - __sinPY;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8116
                                        __nX = __nX + __halfW + 0.5;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8117
                                        __srcX = (int)__nX;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8118
                                    } while (__srcX >= __width);
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8119
                                    __dstX -= FAST_ADVANCE; __dstPtr -= FAST_ADVANCE;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8120
                                }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  8121
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8122
                                __pix = __blackPixel;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8123
                            } else {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8124
                                double __nY;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8125
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8126
                                /* rotate Y */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8127
                                __nY = (__sin * __pX) + __cosPY;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8128
                                /* translate Y in source (origin to 0/0) */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8129
                                __nY = __nY + __halfH + 0.5;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8130
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8131
                                /* inside ? */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8132
                                if (__nY < 0) {
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
  8133
#ifdef EARLY_OUT
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8134
                                    if (didFetchInRow) {
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8135
                                        break;
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8136
                                    }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8137
#endif
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8138
#ifdef FAST_ADVANCE2
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8139
                                    if (__blackPixel == 0) {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8140
                                        do {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8141
                                            /* try advance by FAST_ADVANCE pixels ... */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8142
                                            __dstX += FAST_ADVANCE; __dstPtr += FAST_ADVANCE;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8143
                                            if (__dstX >= __newWidth) {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8144
                                                break;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8145
                                            }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8146
                                            __pX = (double)(__dstX + __minX);
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8147
                                            __nY = (__sin * __pX) + __cosPY;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8148
                                            __nY = __nY + __halfH + 0.5;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8149
                                        } while (__nY < 0);
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8150
                                        __dstX -= FAST_ADVANCE; __dstPtr -= FAST_ADVANCE;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8151
                                    }
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
  8152
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8153
                                    __pix = __blackPixel;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8154
                                } else {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8155
                                    int __srcY;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8156
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8157
                                    __srcY = (int)__nY;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8158
                                    /* inside ? */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8159
                                    if (__srcY >= __height) {
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
  8160
#ifdef EARLY_OUT
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8161
                                        if (didFetchInRow) {
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8162
                                            break;
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8163
                                        }
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8164
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8165
#ifdef FAST_ADVANCE
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8166
                                        if (__blackPixel == 0) {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8167
                                            do {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8168
                                                /* try advance by FAST_ADVANCE pixels ... */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8169
                                                __dstX += FAST_ADVANCE; __dstPtr += FAST_ADVANCE;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8170
                                                if (__dstX >= __newWidth) {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8171
                                                    break;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8172
                                                }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8173
                                                __pX = (double)(__dstX + __minX);
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8174
                                                __nY = (__sin * __pX) + __cosPY;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8175
                                                __nY = __nY + __halfH + 0.5;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8176
                                                __srcY = (int)__nY;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8177
                                            } while (__srcY >= __height);
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8178
                                            __dstX -= FAST_ADVANCE; __dstPtr -= FAST_ADVANCE;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8179
                                        }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8180
#endif
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8181
                                        __pix = __blackPixel;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8182
                                    } else {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8183
                                        /* fetch source pixel */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8184
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8185
                                        int idx;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  8186
#ifdef EARLY_OUT
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8187
                                        didFetchInRow = 1;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  8188
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8189
                                        idx = __srcY * __srcBytesPerRow + __srcX;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8190
                                        if ((unsigned)idx < __nSrcBytes) {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8191
                                            __pix = __srcBytes[idx];
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8192
                                        } else {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8193
                                            __pix = __blackPixel;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8194
                                        }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8195
                                    }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8196
                                }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8197
                            }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8198
                        }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8199
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8200
                        if (__pix != 0) {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8201
                            *__dstPtr = __pix;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8202
                        }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8203
                        __dstPtr++;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8204
                    }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8205
                }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8206
                break;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8207
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8208
            case 1:
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8209
                for (__dstY = 0; __dstY < __newHeight; __dstY++) {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8210
                    double __pY, __sinPY, __cosPY;
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
  8211
#ifdef EARLY_OUT
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8212
                    int didFetchInRow = 0;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  8213
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8214
                    __pY = (double)(__dstY + __minY);
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8215
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8216
                    __sinPY = __sin * __pY;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8217
                    __cosPY = __cos * __pY;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8218
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8219
                    __dstPtr = __dstRowPtr;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8220
                    __dstMask = 0x80;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8221
                    __dstRowPtr += __dstBytesPerRow;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8222
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8223
                    for (__dstX = 0; __dstX < __newWidth; __dstX++) {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8224
                        double __pX, __nX;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8225
                        int __pix;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8226
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8227
                        /* translate X in destination (center to 0/0) */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8228
                        __pX = (double)(__dstX + __minX);
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8229
                        /* rotate X */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8230
                        __nX = (__cos * __pX) - __sinPY;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8231
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8232
                        /* translate X in source (origin to 0/0) */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8233
                        __nX = __nX + __halfW + 0.5;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8234
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8235
                        /* inside ? */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8236
                        if (__nX < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  8237
#ifdef EARLY_OUT
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8238
                            if (didFetchInRow) {
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8239
                                break;
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8240
                            }
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8241
#endif
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8242
#ifdef FAST_ADVANCE
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8243
                            if (__blackPixel == 0) {
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8244
                                do {
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8245
                                    /* try advance by 8 pixels ... */
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8246
                                    __dstX += 8; __dstPtr ++;
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8247
                                    if (__dstX >= __newWidth) {
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8248
                                        break;
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8249
                                    }
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8250
                                    __pX = (double)(__dstX + __minX);
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8251
                                    __nX = (__cos * __pX) - __sinPY;
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8252
                                    __nX = __nX + __halfW + 0.5;
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8253
                                } while (__nX < 0);
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8254
                                __dstX -= 8; __dstPtr--;
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8255
                            }
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8256
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8257
                            __pix = __blackPixel;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8258
                        } else {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8259
                            int __srcX;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8260
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8261
                            __srcX = (int)__nX;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8262
                            /* inside ? */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8263
                            if (__srcX >= __width) {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8264
#ifdef EARLY_OUT
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8265
                                if (didFetchInRow) {
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8266
                                    break;
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8267
                                }
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8268
#endif
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8269
#ifdef FAST_ADVANCE2
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8270
                                if (__blackPixel == 0) {
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8271
                                    do {
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8272
                                        /* try advance by 8 pixels ... */
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8273
                                        __dstX += 8; __dstPtr++;
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8274
                                        if (__dstX >= __newWidth) {
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8275
                                            break;
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8276
                                        }
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8277
                                        __pX = (double)(__dstX + __minX);
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8278
                                        __nX = (__cos * __pX) - __sinPY;
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8279
                                        __nX = __nX + __halfW + 0.5;
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8280
                                        __srcX = (int)__nX;
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8281
                                    } while (__srcX >= __width);
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8282
                                    __dstX -= 8; __dstPtr--;
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8283
                                }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8284
#endif
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8285
                                __pix = __blackPixel;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8286
                            } else {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8287
                                double __nY;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8288
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8289
                                /* rotate Y */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8290
                                __nY = (__sin * __pX) + __cosPY;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8291
                                /* translate Y in source (origin to 0/0) */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8292
                                __nY = __nY + __halfH + 0.5;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8293
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8294
                                /* inside ? */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8295
                                if (__nY < 0) {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8296
#ifdef EARLY_OUT
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8297
                                    if (didFetchInRow) {
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8298
                                        break;
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8299
                                    }
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8300
#endif
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8301
#ifdef FAST_ADVANCE2
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8302
                                    if (__blackPixel == 0) {
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8303
                                        do {
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8304
                                            /* try advance by 8 pixels ... */
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8305
                                            __dstX += 8; __dstPtr++;
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8306
                                            if (__dstX >= __newWidth) {
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8307
                                                break;
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8308
                                            }
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8309
                                            __pX = (double)(__dstX + __minX);
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8310
                                            __nY = (__sin * __pX) + __cosPY;
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8311
                                            __nY = __nY + __halfH + 0.5;
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8312
                                        } while (__nY < 0);
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8313
                                        __dstX -= 8; __dstPtr--;
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8314
                                    }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8315
#endif
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8316
                                    __pix = __blackPixel;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8317
                                } else {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8318
                                    int __srcY;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8319
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8320
                                    __srcY = (int)__nY;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8321
                                    /* inside ? */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8322
                                    if (__srcY >= __height) {
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
  8323
#ifdef EARLY_OUT
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8324
                                        if (didFetchInRow) {
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8325
                                            break;
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8326
                                        }
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8327
#endif
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8328
#ifdef FAST_ADVANCE
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8329
                                        if (__blackPixel == 0) {
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8330
                                            do {
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8331
                                                /* try advance by 8 pixels ... */
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8332
                                                __dstX += 8; __dstPtr++;
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8333
                                                if (__dstX >= __newWidth) {
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8334
                                                    break;
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8335
                                                }
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8336
                                                __pX = (double)(__dstX + __minX);
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8337
                                                __nY = (__sin * __pX) + __cosPY;
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8338
                                                __nY = __nY + __halfH + 0.5;
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8339
                                                __srcY = (int)__nY;
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8340
                                            } while (__srcY >= __height);
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8341
                                            __dstX -= 8; __dstPtr--;
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8342
                                        }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  8343
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8344
                                        __pix = __blackPixel;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8345
                                    } else {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8346
                                        /* fetch source pixel */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8347
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8348
                                        int idx, pV;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  8349
#ifdef EARLY_OUT
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8350
                                        didFetchInRow = 1;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  8351
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8352
                                        idx = __srcY * __srcBytesPerRow + (__srcX >> 3);
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8353
                                        if ((unsigned)idx < __nSrcBytes) {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8354
                                            pV = __srcBytes[idx];
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8355
                                            __pix = (pV & (0x80 >> (__srcX & 7))) ? 1 : 0;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8356
                                        } else {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8357
                                            __pix = __blackPixel;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8358
                                        }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8359
                                    }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8360
                                }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8361
                            }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8362
                        }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8363
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8364
                        /* store pixel */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8365
                        if (__pix != 0) {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8366
                            *__dstPtr |= __dstMask;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8367
                        }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8368
                        __dstMask >>= 1;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8369
                        if (__dstMask == 0) {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8370
                            __dstMask = 0x80;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8371
                            __dstPtr++;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8372
                        }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8373
                    }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8374
                }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8375
                break;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8376
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8377
            case 24:
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8378
                for (__dstY = 0; __dstY < __newHeight; __dstY++) {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8379
                    double __pY, __sinPY, __cosPY;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  8380
#ifdef EARLY_OUT
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8381
                    int didFetchInRow = 0;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  8382
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8383
                    __pY = (double)(__dstY + __minY);
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8384
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8385
                    __sinPY = __sin * __pY;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8386
                    __cosPY = __cos * __pY;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8387
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8388
                    __dstPtr = __dstRowPtr;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8389
                    __dstRowPtr += __dstBytesPerRow;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8390
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8391
                    for (__dstX = 0; __dstX < __newWidth; __dstX++) {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8392
                        double __pX, __nX;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8393
                        unsigned __pix;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8394
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8395
                        /* translate X in destination (center to 0/0) */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8396
                        __pX = (double)(__dstX + __minX);
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8397
                        /* rotate X */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8398
                        __nX = (__cos * __pX) - __sinPY;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8399
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8400
                        /* translate X in source (origin to 0/0) */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8401
                        __nX = __nX + __halfW + 0.5;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8402
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8403
                        /* inside ? */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8404
                        if (__nX < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  8405
#ifdef EARLY_OUT
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8406
                            if (didFetchInRow) {
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8407
                                break;
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8408
                            }
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
  8409
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8410
                            __pix = __blackPixel;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8411
                        } else {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8412
                            int __srcX;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8413
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8414
                            __srcX = (int)__nX;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8415
                            /* inside ? */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8416
                            if (__srcX >= __width) {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8417
#ifdef EARLY_OUT
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8418
                                if (didFetchInRow) {
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8419
                                    break;
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8420
                                }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8421
#endif
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8422
                                __pix = __blackPixel;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8423
                            } else {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8424
                                double __nY;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8425
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8426
                                /* rotate Y */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8427
                                __nY = (__sin * __pX) + __cosPY;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8428
                                /* translate Y in source (origin to 0/0) */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8429
                                __nY = __nY + __halfH + 0.5;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8430
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8431
                                /* inside ? */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8432
                                if (__nY < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  8433
#ifdef EARLY_OUT
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8434
                                    if (didFetchInRow) {
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8435
                                        break;
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8436
                                    }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8437
#endif
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8438
                                    __pix = __blackPixel;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8439
                                } else {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8440
                                    int __srcY;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8441
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8442
                                    __srcY = (int)__nY;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8443
                                    /* inside ? */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8444
                                    if (__srcY >= __height) {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8445
#ifdef EARLY_OUT
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8446
                                        if (didFetchInRow) {
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8447
                                            break;
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8448
                                        }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8449
#endif
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8450
                                        __pix = __blackPixel;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8451
                                    } else {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8452
                                        /* fetch source pixel */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8453
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8454
                                        int idx;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8455
#ifdef EARLY_OUT
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8456
                                        didFetchInRow = 1;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  8457
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8458
                                        idx = __srcY * __srcBytesPerRow + __srcX + __srcX + __srcX;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8459
                                        if ((unsigned)idx < __nSrcBytes) {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8460
                                            __pix = __srcBytes[idx];
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8461
                                            __pix = (__pix<<8) | __srcBytes[idx+1];
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8462
                                            __pix = (__pix<<8) | __srcBytes[idx+2];
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8463
                                        } else {
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8464
                                            __pix = __blackPixel;
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8465
                                        }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8466
                                    }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8467
                                }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8468
                            }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8469
                        }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8470
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8471
                        /* store pixel */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8472
                        if (__pix != 0) {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8473
                            __dstPtr[0] = (__pix >> 16 & 0xFF);
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8474
                            __dstPtr[1] = (__pix >> 8) & 0xFF;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8475
                            __dstPtr[2] = __pix & 0xFF;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8476
                        }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8477
                        __dstPtr += 3;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8478
                    }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8479
                }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8480
                break;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8481
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8482
            default:
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8483
                for (__dstY = 0; __dstY < __newHeight; __dstY++) {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8484
                    double __pY, __sinPY, __cosPY;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  8485
#ifdef EARLY_OUT
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8486
                    int didFetchInRow = 0;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  8487
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8488
                    __pY = (double)(__dstY + __minY);
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8489
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8490
                    __sinPY = __sin * __pY;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8491
                    __cosPY = __cos * __pY;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8492
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8493
                    __dstPtr = __dstRowPtr;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8494
                    __dstMask = 0x80;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8495
                    __dstRowPtr += __dstBytesPerRow;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8496
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8497
                    for (__dstX = 0; __dstX < __newWidth; __dstX++) {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8498
                        double __pX, __nX;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8499
                        OBJ __pix;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8500
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8501
                        /* translate X in destination (center to 0/0) */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8502
                        __pX = (double)(__dstX + __minX);
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8503
                        /* rotate X */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8504
                        __nX = (__cos * __pX) - __sinPY;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8505
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8506
                        /* translate X in source (origin to 0/0) */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8507
                        __nX = __nX + __halfW + 0.5;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8508
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8509
                        /* inside ? */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8510
                        if (__nX < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  8511
#ifdef EARLY_OUT
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8512
                            if (didFetchInRow) {
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8513
                                break;
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8514
                            }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  8515
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8516
                            __pix = blackPixel;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8517
                        } else {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8518
                            int __srcX;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8519
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8520
                            __srcX = (int)__nX;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8521
                            /* inside ? */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8522
                            if (__srcX >= __width) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  8523
#ifdef EARLY_OUT
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8524
                                if (didFetchInRow) {
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8525
                                    break;
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8526
                                }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  8527
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8528
                                __pix = blackPixel;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8529
                            } else {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8530
                                double __nY;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8531
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8532
                                /* rotate Y */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8533
                                __nY = (__sin * __pX) + __cosPY;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8534
                                /* translate Y in source (origin to 0/0) */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8535
                                __nY = __nY + __halfH + 0.5;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8536
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8537
                                /* inside ? */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8538
                                if (__nY < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  8539
#ifdef EARLY_OUT
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8540
                                    if (didFetchInRow) {
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8541
                                        break;
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8542
                                    }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  8543
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8544
                                    __pix = blackPixel;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8545
                                } else {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8546
                                    int __srcY;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8547
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8548
                                    __srcY = (int)__nY;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8549
                                    /* inside ? */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8550
                                    if (__srcY >= __height) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  8551
#ifdef EARLY_OUT
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8552
                                        if (didFetchInRow) {
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8553
                                            break;
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8554
                                        }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  8555
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8556
                                        __pix = blackPixel;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8557
                                    } else {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8558
                                        /* fetch source pixel */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8559
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8560
                                        static struct inlineCache valAt = _ILC2;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8561
#ifdef EARLY_OUT
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8562
                                        didFetchInRow = 1;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8563
#endif
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8564
                                        __pix = (*valAt.ilc_func)(self,
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8565
                                                              @symbol(pixelAtX:y:),
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8566
                                                              nil, &valAt,
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8567
                                                              __MKSMALLINT(__srcX),
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8568
                                                              __MKSMALLINT(__srcY));
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8569
                                    }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8570
                                }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8571
                            }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8572
                        }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8573
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8574
                        /* store pixel */
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8575
                        {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8576
                            static struct inlineCache atPutVal = _ILC3;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8577
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8578
                            if (__pix != __MKSMALLINT(0)) {
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8579
                                (*atPutVal.ilc_func)(newImage,
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8580
                                                      @symbol(pixeAtX:y:put:),
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8581
                                                      nil, &atPutVal,
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8582
                                                      __MKSMALLINT(__dstX),
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8583
                                                      __MKSMALLINT(__dstY),
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8584
                                                      __pix
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8585
                                                     );
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8586
                            }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8587
                        }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8588
                    }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8589
                }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8590
                break;
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8591
        }
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8592
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8593
        bad = false;
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8594
    }
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8595
%}.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8596
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8597
    bad ifTrue:[
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8598
        "/ should not happen
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8599
        self primitiveFailed
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8600
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8601
"/        sinRot := radians negated sin.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8602
"/        cosRot := radians negated cos.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8603
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8604
"/        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
  8605
"/            pY := (dstY + minY).
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8606
"/            sinPY := (sinRot * pY).
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8607
"/            cosPY := (cosRot * pY).
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8608
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8609
"/            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
  8610
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8611
"/                "/ translate center to origin
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8612
"/                pX := (dstX + minX).
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8613
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8614
"/                nX := (cosRot * pX) - sinPY.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8615
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8616
"/                "/ translate in source
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8617
"/                srcX := nX + halfW.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8618
"/                srcX := srcX rounded.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8619
"/                "/ inside ?
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8620
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8621
"/                (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
  8622
"/                    nY := (sinRot * pX) + cosPY.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8623
"/                    srcY := nY + halfH.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8624
"/                    srcY := srcY rounded.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8625
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8626
"/                    "/ inside ?
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8627
"/                    (srcY >= 0 and:[srcY < height]) ifTrue:[
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8628
"/                        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
  8629
"/                    ] ifFalse:[
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8630
"/                        pix := blackPixel.        
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8631
"/                    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8632
"/                ] ifFalse:[
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8633
"/                    pix := blackPixel.        
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8634
"/                ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8635
"/                pix ~~ blackPixel ifTrue:[
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8636
"/                    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
  8637
"/                ]
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8638
"/            ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8639
"/        ].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8640
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8641
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8642
    ^ newImage
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8643
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8644
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8645
     |i|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8646
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8647
     i := Image fromFile:'bitmaps/xpmBitmaps/BOOK.xpm'.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8648
     i inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8649
     (i rotated:45) inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8650
     (i rotated:90) inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8651
     (i rotated:91) inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8652
     (i rotated:95) inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8653
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8654
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8655
     |i|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8656
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8657
     i := Image fromFile:'bitmaps/gifImages/garfield.gif'.
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8658
     i := Depth24Image fromImage:i.
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8659
     (i rotated:200) inspect
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8660
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8661
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8662
     |i|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8663
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8664
     i := Image fromFile:'bitmaps/gifImages/garfield.gif'.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8665
     Transcript showCR:(
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8666
        Time millisecondsToRun:[
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8667
           i rotated:45.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8668
        ]
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8669
     ).
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8670
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8671
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8672
     |v i rI rot|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8673
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8674
     i := Image fromFile:'bitmaps/xpmBitmaps/BOOK.xpm'.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8675
     v := View new extent:(i width max:100)@(i height max:100).
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8676
     v openAndWait.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8677
     rot := 0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8678
     [true] whileTrue:[
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8679
        rI := i rotated:rot.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8680
        rI := rI on:v device.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8681
        v clear.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8682
        v displayForm:rI x:v width//2-(rI width//2) y:v height//2-(rI height // 2).
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8683
        rot := rot + 5.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8684
        rI close.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8685
     ]
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8686
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8687
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8688
     |v i rI rot|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8689
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8690
     i := Image fromFile:'bitmaps/gifImages/claus.gif'.
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  8691
     v := View new extent:400@400.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8692
     v openAndWait.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8693
     rot := 0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8694
     [true] whileTrue:[
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8695
        rI := i rotated:rot.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8696
        rI := rI on:v device.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8697
        v clear.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8698
        v displayForm:rI x:v width//2-(rI width//2) y:v height//2-(rI height // 2).
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8699
        rot := rot + 5.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  8700
        rI close.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8701
     ]
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8702
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8703
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8704
    "Modified: 22.4.1997 / 17:36:37 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8705
!
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8706
54
29a6b2f8e042 *** empty log message ***
claus
parents: 46
diff changeset
  8707
lightened
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  8708
    "return a new image which is slightly brighter than the receiver.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  8709
     The receiver must be a palette image (currently).
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8710
     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
  8711
     CAVEAT: Need an argument, which specifies by how much it should be lighter."
54
29a6b2f8e042 *** empty log message ***
claus
parents: 46
diff changeset
  8712
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8713
     ^ self 
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8714
        copyWithColorMapProcessing:[:clr | clr lightened]
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8715
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8716
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8717
     (Image fromFile:'bitmaps/gifImages/claus.gif') inspect
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8718
     (Image fromFile:'bitmaps/gifImages/claus.gif') lightened inspect
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8719
     (Image fromFile:'bitmaps/gifImages/claus.gif') darkened inspect
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8720
     (Image fromFile:'bitmaps/gifImages/claus.gif') darkened darkened inspect
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8721
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8722
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8723
    "Modified: 24.4.1997 / 18:31:23 / cg"
54
29a6b2f8e042 *** empty log message ***
claus
parents: 46
diff changeset
  8724
!
29a6b2f8e042 *** empty log message ***
claus
parents: 46
diff changeset
  8725
134
claus
parents: 132
diff changeset
  8726
magnifiedBy:scale
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8727
    "return a new image magnified by scalePoint, aPoint.
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  8728
     If non-integral magnify is asked for, pass the work on to 'hardMagnifyBy:'
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  8729
     while simple (integral) magnifications are handled here."
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  8730
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8731
    |scalePoint mX mY
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  8732
     magX      "{ Class: SmallInteger }"   "new version of stc can find this out itself..."
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  8733
     magY      "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  8734
     srcOffset "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  8735
     dstOffset "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  8736
     w         "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  8737
     h         "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  8738
     first
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  8739
     newWidth newHeight newImage newBits newMask
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8740
     bitsPerPixel newBytesPerRow oldBytesPerRow|
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  8741
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8742
    scalePoint := scale asPoint.
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8743
    mX := scalePoint asPoint x.
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8744
    mY := scalePoint asPoint y.
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  8745
    ((mX <= 0) or:[mY <= 0]) ifTrue:[^ nil].
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  8746
    ((mX = 1) and:[mY = 1]) ifTrue:[^ self].
48194c26a46c Initial revision
claus
parents:
diff changeset
  8747
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  8748
    ((mX isMemberOf:SmallInteger) and:[mY isMemberOf:SmallInteger]) ifFalse:[
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8749
        ^ self hardMagnifiedBy:scalePoint
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  8750
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
  8751
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  8752
    bitsPerPixel := self depth.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  8753
    oldBytesPerRow := ((width * bitsPerPixel) + 7) // 8.
48194c26a46c Initial revision
claus
parents:
diff changeset
  8754
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  8755
    w := width.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  8756
    h := height.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  8757
    magX := mX.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  8758
    magY := mY.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  8759
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  8760
    newWidth := w * mX.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  8761
    newHeight := h * mY.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  8762
    newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8.
48194c26a46c Initial revision
claus
parents:
diff changeset
  8763
    newBits := ByteArray uninitializedNew:(newBytesPerRow * newHeight).
48194c26a46c Initial revision
claus
parents:
diff changeset
  8764
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  8765
    mask notNil ifTrue:[
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8766
        newMask := (mask magnifiedBy:scalePoint)
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  8767
    ].
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  8768
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  8769
    newImage := self species new.
905
228d503775d9 everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents: 904
diff changeset
  8770
    newImage 
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8771
        width:newWidth 
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8772
        height:newHeight 
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8773
        photometric:photometric 
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8774
        samplesPerPixel:samplesPerPixel 
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8775
        bitsPerSample:bitsPerSample 
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8776
        colorMap:colorMap copy
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8777
        bits:newBits
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8778
        mask:newMask.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  8779
48194c26a46c Initial revision
claus
parents:
diff changeset
  8780
    mX = 1 ifTrue:[
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8781
        "expand rows only"
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8782
        srcOffset := 1.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8783
        dstOffset := 1.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8784
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8785
        1 to:h do:[:row |
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8786
            1 to:mY do:[:i |
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8787
                newBits replaceFrom:dstOffset 
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8788
                        to:(dstOffset + oldBytesPerRow - 1)
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8789
                        with:bytes 
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8790
                        startingAt:srcOffset.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8791
                dstOffset := dstOffset + newBytesPerRow
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8792
            ].
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8793
            srcOffset := srcOffset + oldBytesPerRow.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8794
        ].
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  8795
    ] ifFalse:[
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8796
        "expand cols"
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8797
        (mX > 1) ifTrue:[
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8798
            dstOffset := 1.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8799
            srcOffset := 1.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8800
            1 to:h do:[:row |
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8801
                self magnifyRowFrom:bytes 
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8802
                     offset:srcOffset  
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8803
                     into:newBits 
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8804
                     offset:dstOffset 
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8805
                     factor:mX.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8806
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8807
                first := dstOffset.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8808
                dstOffset := dstOffset + newBytesPerRow.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8809
                " and copy for row expansion "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8810
                2 to:mY do:[:i |
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8811
                    newBits replaceFrom:dstOffset 
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8812
                            to:(dstOffset + newBytesPerRow - 1)
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8813
                            with:newBits 
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8814
                            startingAt:first.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8815
                    dstOffset := dstOffset + newBytesPerRow
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8816
                ].
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8817
                srcOffset := srcOffset + oldBytesPerRow.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8818
            ].
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8819
        ]
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  8820
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
  8821
    ^ newImage
48194c26a46c Initial revision
claus
parents:
diff changeset
  8822
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8823
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8824
     ((Image fromFile:'bitmaps/gifImages/claus.gif') magnifiedBy:1@2)
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8825
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8826
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8827
    "Modified: 24.4.1997 / 18:32:04 / cg"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  8828
!
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  8829
154
claus
parents: 153
diff changeset
  8830
magnifiedPreservingRatioTo:anExtent 
claus
parents: 153
diff changeset
  8831
    "return a new image magnified to fit into anExtent,
claus
parents: 153
diff changeset
  8832
     preserving the receivers width/height ratio.
claus
parents: 153
diff changeset
  8833
     (i.e. not distorting the image).
claus
parents: 153
diff changeset
  8834
     See also #magnifiedTo: and #magnifiedBy:"
claus
parents: 153
diff changeset
  8835
claus
parents: 153
diff changeset
  8836
    |rX rY|
claus
parents: 153
diff changeset
  8837
claus
parents: 153
diff changeset
  8838
    rX := anExtent x / self width.
claus
parents: 153
diff changeset
  8839
    rY := anExtent y / self height.
claus
parents: 153
diff changeset
  8840
    ^ self magnifiedBy:(rX min:rY)
claus
parents: 153
diff changeset
  8841
claus
parents: 153
diff changeset
  8842
    "
1630
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  8843
     ((Image fromFile:'bitmaps/gifImages/garfield.gif') magnifiedPreservingRatioTo:100@100)
154
claus
parents: 153
diff changeset
  8844
claus
parents: 153
diff changeset
  8845
    in contrast to:
claus
parents: 153
diff changeset
  8846
1630
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  8847
     ((Image fromFile:'bitmaps/gifImages/garfield.gif') magnifiedTo:100@100)
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  8848
    "
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  8849
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  8850
    "Modified: 22.4.1997 / 12:33:46 / cg"
154
claus
parents: 153
diff changeset
  8851
!
claus
parents: 153
diff changeset
  8852
134
claus
parents: 132
diff changeset
  8853
magnifiedTo:anExtent 
154
claus
parents: 153
diff changeset
  8854
    "return a new image magnified to have the size specified by extent.
claus
parents: 153
diff changeset
  8855
     This may distort the image if the arguments ratio is not the images ratio.
claus
parents: 153
diff changeset
  8856
     See also #magnifiedPreservingRatioTo: and #magnifiedBy:"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  8857
134
claus
parents: 132
diff changeset
  8858
    ^ self magnifiedBy:(anExtent / self extent)
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  8859
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  8860
    "
134
claus
parents: 132
diff changeset
  8861
     ((Image fromFile:'bitmaps/garfield.gif') magnifiedTo:100@100)
154
claus
parents: 153
diff changeset
  8862
claus
parents: 153
diff changeset
  8863
    in contrast to:
claus
parents: 153
diff changeset
  8864
claus
parents: 153
diff changeset
  8865
     ((Image fromFile:'bitmaps/garfield.gif') magnifiedPreservingRatioTo:100@100)
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  8866
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  8867
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  8868
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  8869
rotated:degrees
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  8870
    "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
  8871
     degrees clockwise.
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8872
     Notice, that the resulting image has a different extent.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8873
     If rotation is heavily used, the workHorse methods
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8874
     (#easyRotateBitsInto:angle: and #hardRotateBitsInto:angle) may
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8875
     be redefined in concrete image subclasses."
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8876
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8877
    |nW nH newImage newBits newBytesPerRow d|
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  8878
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  8879
    d := degrees.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  8880
    [d < 0] whileTrue:[d := d + 360].
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  8881
    d >= 360 ifTrue:[d := d \\ 360].
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  8882
    d := d truncated.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8883
    d = 0 ifTrue:[^ self].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8884
    ((d ~= 90) and:[(d ~= 270) and:[d ~= 180]]) ifTrue:[
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8885
        ^ self hardRotated:d
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  8886
    ].
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  8887
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8888
    d = 180 ifTrue:[
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8889
        nW := width.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8890
        nH := height.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8891
    ] ifFalse:[
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8892
        nW := height.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8893
        nH := width.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8894
    ].
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  8895
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  8896
    newImage := self species new.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8897
    newImage width:nW.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8898
    newImage height:nH.
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8899
    newBytesPerRow := newImage bytesPerRow.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8900
    newBits := ByteArray uninitializedNew:(newBytesPerRow * nH).
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8901
    newImage bits:newBits.
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  8902
    newImage photometric:photometric.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  8903
    newImage samplesPerPixel:samplesPerPixel.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  8904
    newImage bitsPerSample:bitsPerSample.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  8905
    newImage colorMap:colorMap copy.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8906
    mask notNil ifTrue:[
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8907
        newImage mask:(mask rotated:degrees)
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8908
    ].
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8909
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8910
    self easyRotateBitsInto:newImage angle:d.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8911
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  8912
    ^ newImage
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  8913
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8914
    "
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8915
     |i|
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8916
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  8917
     i := Image fromFile:'bitmaps/gifImages/claus.gif'.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8918
     i inspect.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8919
     (i rotated:45) inspect.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8920
     (i rotated:90) inspect.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8921
     (i rotated:180) inspect.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8922
     (i rotated:270) inspect.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8923
    "
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8924
    "
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8925
     |i|
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8926
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8927
     i := Image fromFile:'bitmaps/xpmBitmaps/BOOK.xpm'.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8928
     i inspect.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8929
     (i rotated:90) inspect.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8930
     (i rotated:180) inspect.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8931
     (i rotated:270) inspect.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8932
    "
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8933
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8934
    "Modified: 24.4.1997 / 18:33:42 / cg"
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8935
!
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8936
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8937
withPixelFunctionApplied:pixelFunctionBlock
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8938
    "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
  8939
     on the pixel colors.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8940
     Notice: this method is very slow - either apply pixel values
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8941
     (#withPixelFunctionAppliedToPixels:) or redefine this method in
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8942
     a concrete subclass.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8943
     (read `Behond photography, by Gerard J. Holzmann;
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8944
           ISBM 0-13-074410-7)
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8945
     See blurred / oilPointed as examples ...)"
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8946
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8947
    |w  "{Class: SmallInteger }"
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8948
     h  "{Class: SmallInteger }"
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  8949
     newImage newBits newBytesPerRow|
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8950
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8951
    newBytesPerRow := ((width * self depth) + 7) // 8.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8952
    newBits := ByteArray uninitializedNew:(newBytesPerRow * height).
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8953
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8954
    newImage := self species new.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8955
    newImage bits:newBits.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8956
    newImage width:width.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8957
    newImage height:height.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8958
    newImage photometric:photometric.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8959
    newImage samplesPerPixel:samplesPerPixel.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8960
    newImage bitsPerSample:bitsPerSample.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8961
    newImage colorMap:colorMap copy.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8962
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8963
    w := width - 1.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8964
    h := height - 1.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8965
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8966
    0 to:h do:[:y |
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8967
        0 to:w do:[:x |
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8968
            newImage colorAtX:x y:y put:(pixelFunctionBlock
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8969
                                                value:self
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8970
                                                value:(self colorAtX:x y:y)
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8971
                                                value:x
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8972
                                                value:y)
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8973
        ]
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8974
    ].
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8975
    ^ newImage
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8976
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8977
    "
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
  8978
     |i black|
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8979
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  8980
     i := Image fromFile:'bitmaps/gifImages/claus.gif'.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8981
     i inspect.
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
  8982
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
  8983
     black := Color black.
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
  8984
     (i withPixelFunctionApplied:[:oldImage :oldColor :x :y |
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8985
                        ((x between:100 and:200) 
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8986
                        and:[y between:100 and:200]) ifTrue:[
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8987
                            oldColor
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8988
                        ] ifFalse:[
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8989
                            black.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8990
                        ]
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8991
                     ]) inspect.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8992
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8993
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8994
    "Modified: 24.4.1997 / 18:36:59 / cg"
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8995
!
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8996
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8997
withPixelFunctionAppliedToPixels:pixelFunctionBlock
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  8998
    "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
  8999
     on the pixel values.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  9000
     (read `Behond photography, by Gerard J. Holzmann;
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9001
           ISBM 0-13-074410-7)
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  9002
     See blurred / oilPointed as examples ...)"
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  9003
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
  9004
    |newImage newBits newBytesPerRow|
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  9005
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  9006
    newBytesPerRow := ((width * self depth) + 7) // 8.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  9007
    newBits := ByteArray uninitializedNew:(newBytesPerRow * height).
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  9008
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  9009
    newImage := self species new.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  9010
    newImage bits:newBits.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  9011
    newImage width:width.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  9012
    newImage height:height.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  9013
    newImage photometric:photometric.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  9014
    newImage samplesPerPixel:samplesPerPixel.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  9015
    newImage bitsPerSample:bitsPerSample.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  9016
    newImage colorMap:colorMap copy.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  9017
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
  9018
    self applyPixelValuesTo:pixelFunctionBlock into:newImage.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  9019
    ^ newImage
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  9020
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  9021
    "oil painting effect:
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  9022
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  9023
     |i w h|
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  9024
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  9025
     i := Image fromFile:'bitmaps/gifImages/claus.gif'.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  9026
     i inspect.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  9027
     w := i width - 1.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  9028
     h := i height - 1.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9029
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9030
                        |b p max xMin xMax yMin yMax|
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9031
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9032
                        b := Bag identityNew:10.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9033
                        xMin := x-3 max:0.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9034
                        xMax := x+3 min:w.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9035
                        yMin := y-3 max:0.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9036
                        yMax := y+3 min:h.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9037
                        xMin to:xMax do:[:tx|
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9038
                          yMin to:yMax do:[:ty|
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9039
                            b add:(oldImage pixelAtX:tx y:ty)
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9040
                          ]
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9041
                        ].
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9042
                        max := 0.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9043
                        b contents keysAndValuesDo:[:pixel :n |
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9044
                            n > max ifTrue:[
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9045
                                p := pixel.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9046
                                max := n
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9047
                            ]
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9048
                        ].
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9049
                        p
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9050
                     ]) inspect.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  9051
    "
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  9052
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  9053
    "fisheye effect:
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  9054
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
  9055
     |i w h w2 h2 R white|
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  9056
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  9057
     i := Image fromFile:'bitmaps/gifImages/claus.gif'.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  9058
     i inspect.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  9059
     w := i width - 1.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  9060
     h := i height - 1.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  9061
     w2 := w // 2.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  9062
     h2 := h // 2.
1510
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
  9063
     R := w2.
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
  9064
     white := i valueFromColor:Color white.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9065
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9066
                        |p r a nR nP nX nY|
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9067
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9068
                        p := (x-w2)@(y-h2).
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9069
                        r := p r.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9070
                        a := p theta.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9071
                        nR := r * r / R.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9072
                        nP := Point r:nR theta:a.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9073
                        nX := ((nP x+w2) rounded max:0) min:w.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9074
                        nY := ((nP y+h2) rounded max:0) min:h.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9075
                        (nX > w or:[nX < 0]) ifTrue:[
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9076
                            white
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9077
                        ] ifFalse:[
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9078
                            (nY > h or:[nY < 0]) ifTrue:[
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9079
                                white
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9080
                            ] ifFalse:[
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9081
                                oldImage pixelAtX:nX y:nY
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9082
                            ]
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9083
                        ]
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9084
                     ]) inspect.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
  9085
    "
1510
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
  9086
    "fisheye effect:
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
  9087
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
  9088
     |i w h w2 h2 R white|
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
  9089
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
  9090
     i := Image fromFile:'bitmaps/gifImages/claus.gif'.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
  9091
     i inspect.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
  9092
     w := i width - 1.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
  9093
     h := i height - 1.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
  9094
     w2 := w // 2.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
  9095
     h2 := h // 2.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
  9096
     R := w2.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
  9097
     white := i valueFromColor:Color white.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9098
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9099
                        |p r a nR nP nX nY|
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9100
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9101
                        p := (x-w2)@(y-h2).
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9102
                        r := p r.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9103
                        a := p theta.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9104
                        nR := r * r / R.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9105
                        nP := Point r:nR theta:a.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9106
                        nX := (nP x+w2) rounded.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9107
                        nY := (nP y+h2) rounded.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9108
                        (nX > w or:[nX < 0]) ifTrue:[
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9109
                            white
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9110
                        ] ifFalse:[
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9111
                            (nY > h or:[nY < 0]) ifTrue:[
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9112
                                white
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9113
                            ] ifFalse:[
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9114
                                oldImage pixelAtX:nX y:nY
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9115
                            ]
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9116
                        ]
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9117
                     ]) inspect.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9118
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9119
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9120
    "Created: 24.4.1997 / 18:37:17 / cg"
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9121
    "Modified: 24.4.1997 / 18:40:02 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9122
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9123
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9124
!Image methodsFor:'inspecting'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9125
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9126
inspectorClass
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9127
    "redefined to launch an ImageInspector
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9128
     (instead of the default InspectorView)."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9129
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  9130
    (width notNil and:[height notNil]) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9131
	^ ImageInspectorView
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  9132
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  9133
    ^ super inspectorClass
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  9134
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  9135
    "Modified: 10.6.1996 / 18:23:55 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9136
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9137
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9138
!Image methodsFor:'instance release'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9139
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9140
close
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9141
    "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
  9142
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9143
    deviceForm notNil ifTrue:[
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9144
        deviceForm destroy.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9145
        deviceForm := nil.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9146
    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9147
    monoDeviceForm notNil ifTrue:[
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9148
        monoDeviceForm destroy.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9149
        monoDeviceForm := nil.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9150
    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9151
    fullColorDeviceForm notNil ifTrue:[
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9152
        fullColorDeviceForm destroy.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9153
        fullColorDeviceForm := nil.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9154
    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9155
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9156
    device := nil.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9157
    mask notNil ifTrue:[
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9158
        mask close.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9159
    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9160
    Lobby unregister:self.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9161
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9162
    "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
  9163
    "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
  9164
!
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9165
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9166
disposed
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9167
    "some Image has been collected - nothing to do"
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  9168
!
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  9169
1230
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  9170
quickRelease
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  9171
    "release device resources"
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  9172
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  9173
    device := nil.
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  9174
    deviceForm := nil.
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  9175
    monoDeviceForm := nil.
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  9176
    fullColorDeviceForm := nil.
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  9177
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  9178
    "Modified: 16.1.1997 / 19:33:01 / cg"
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  9179
!
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  9180
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9181
release
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9182
    "release device resources"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9183
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9184
    device := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9185
    deviceForm := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9186
    monoDeviceForm := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9187
    fullColorDeviceForm := nil.
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
  9188
    mask notNil ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9189
	mask release.
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
  9190
    ].
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
  9191
    Lobby unregister:self.
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
  9192
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
  9193
    "Modified: 21.6.1996 / 19:08:19 / cg"
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  9194
!
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  9195
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9196
restored
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9197
    "flush device specifics after a snapin or binary restore"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9198
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9199
    self release
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9200
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9201
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  9202
!Image methodsFor:'obsolete'!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  9203
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  9204
magnifyBy:scale
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  9205
    "obsolete: has been renamed to magnifiedBy: for ST-80 compatibility
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  9206
     and name consistency ..."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  9207
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  9208
    self obsoleteMethodWarning.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  9209
    ^ self magnifiedBy:scale
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  9210
! !
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  9211
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9212
!Image methodsFor:'pixel copying'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9213
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9214
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
  9215
    "replace a rectangular area by pixels from another image.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9216
     WARNING:
1248
6afcdec18986 commentary
Claus Gittinger <cg@exept.de>
parents: 1230
diff changeset
  9217
6afcdec18986 commentary
Claus Gittinger <cg@exept.de>
parents: 1230
diff changeset
  9218
     This implementation is a very slow fallback general algorithm
6afcdec18986 commentary
Claus Gittinger <cg@exept.de>
parents: 1230
diff changeset
  9219
     (the loop over the source pixels is very slow).
6afcdec18986 commentary
Claus Gittinger <cg@exept.de>
parents: 1230
diff changeset
  9220
     If this method is used heavily, you may want to redefine it in 
6afcdec18986 commentary
Claus Gittinger <cg@exept.de>
parents: 1230
diff changeset
  9221
     concrete subclasses for the common case of of copying from an Image 
6afcdec18986 commentary
Claus Gittinger <cg@exept.de>
parents: 1230
diff changeset
  9222
     with the same depth & palette.
6afcdec18986 commentary
Claus Gittinger <cg@exept.de>
parents: 1230
diff changeset
  9223
     If you do heavy image processing, specialized versions are even req'd 
6afcdec18986 commentary
Claus Gittinger <cg@exept.de>
parents: 1230
diff changeset
  9224
     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
  9225
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9226
    |dX dY|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9227
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9228
    dX := srcX-dstX.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9229
    dY := srcY-dstY.
1248
6afcdec18986 commentary
Claus Gittinger <cg@exept.de>
parents: 1230
diff changeset
  9230
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9231
    ((photometric == anImage photometric)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9232
     and:[self bitsPerPixel == anImage bitsPerPixel
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9233
     and:[colorMap = anImage colorMap]]) ifTrue:[
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9234
        "/ can loop over values
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9235
        anImage valuesFromX:srcX  y:srcY 
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9236
                        toX:srcX+w-1 y:srcY+h-1  
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9237
                         do:[:x :y :pixelValue |
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9238
            self pixelAtX:x-dX y:y-dY put:pixelValue.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9239
        ]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9240
    ] ifFalse:[
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9241
        "/ must loop over colors - horribly slow
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9242
        anImage colorsFromX:srcX  y:srcY 
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9243
                        toX:srcX+w-1 y:srcY+h-1  
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9244
                         do:[:x :y :clr |
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9245
            self atX:x-dX y:y-dY put:clr.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9246
        ]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9247
    ]
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9248
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9249
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9250
     |i1 i8 i4|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9251
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9252
     i8 := Image fromFile:'bitmaps/garfield.gif'.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9253
     i8 inspect.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9254
     i1 := Image fromFile:'bitmaps/SBrowser.xbm'.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9255
     i1 inspect.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9256
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9257
     i4 := Depth4Image fromImage:i8.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9258
     i4 copyFrom:i1 x:0 y:0 toX:20 y:20 width:30 height:30.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9259
     i4 inspect.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9260
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9261
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9262
    "Created: 20.9.1995 / 10:14:01 / claus"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9263
    "Modified: 20.9.1995 / 10:25:31 / claus"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9264
    "Modified: 24.4.1997 / 17:27:14 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9265
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9266
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9267
subImageIn:aRectangle
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9268
    "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
  9269
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9270
    ^ self class fromSubImage:self in:aRectangle
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9271
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9272
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9273
     |i|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9274
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9275
     i := Image fromFile:'bitmaps/garfield.gif'.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9276
     i inspect.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9277
     (i subImageIn:(300@160 corner:340@200)) inspect
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9278
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9279
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9280
    "Created: 20.9.1995 / 01:24:20 / claus"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9281
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9282
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9283
!Image methodsFor:'printing & storing'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9284
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9285
storeOn:aStream
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  9286
    "append a printed representation of the receiver to aStream,
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  9287
     from which a copy of it can be reconstructed."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  9288
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9289
    aStream nextPutAll:'(' , self class name , ' new)'.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9290
    aStream nextPutAll:' width: '. width storeOn:aStream.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9291
    aStream nextPutAll:'; height: '. height storeOn:aStream.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9292
    aStream nextPutAll:'; photometric:('. photometric storeOn:aStream.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9293
    aStream nextPutAll:'); bitsPerSample:('. bitsPerSample storeOn:aStream.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9294
    aStream nextPutAll:'); samplesPerPixel:('. samplesPerPixel storeOn:aStream. 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9295
    aStream nextPutAll:'); bits:('. bytes storeOn:aStream. aStream nextPutAll:') '.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9296
    colorMap notNil ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9297
	aStream nextPutAll:'; colorMap:('.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9298
	colorMap storeOn:aStream.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9299
	aStream nextPutAll:')'.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9300
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9301
    aStream nextPutAll:'; yourself'
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  9302
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  9303
    "Modified: 23.4.1996 / 11:18:05 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  9304
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
  9305
48194c26a46c Initial revision
claus
parents:
diff changeset
  9306
!Image methodsFor:'private'!
48194c26a46c Initial revision
claus
parents:
diff changeset
  9307
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  9308
bestSupportedImageFormatFor:aDevice
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  9309
    "scan through the image formats as supported by aDevice,
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  9310
     and return the best to use when the receiver is to be represented
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  9311
     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
  9312
     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
  9313
1595
af720ba3d32c removed unused locals
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
  9314
    |bestDeviceDepth bestDeviceBitsPerPixel bestInfo maxInfo myDepth "maxDepth" maxBitsPerPixel |
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  9315
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  9316
    myDepth := self bitsPerPixel.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  9317
    maxBitsPerPixel := 0.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  9318
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  9319
    aDevice supportedImageFormats do:[:entry |
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9320
	|deviceImageDepth deviceImageBitsPerPixel|
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9321
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9322
	deviceImageDepth := entry at:#depth.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9323
	deviceImageBitsPerPixel := entry at:#bitsPerPixel.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9324
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9325
	deviceImageBitsPerPixel > maxBitsPerPixel ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9326
	    maxInfo := entry.
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  9327
"/            maxBitsPerPixel := deviceImageBitsPerPixel.
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  9328
"/            maxDepth := deviceImageDepth.
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9329
	].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9330
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9331
	deviceImageDepth >= myDepth ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9332
	    deviceImageDepth == myDepth ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9333
		"/ take the better one ...
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9334
		(bestDeviceDepth isNil
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9335
		 or:[(bestDeviceBitsPerPixel ~~ bestDeviceDepth)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9336
		    and:[deviceImageDepth == deviceImageBitsPerPixel]]) ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9337
		    bestInfo := entry.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9338
		    bestDeviceDepth := deviceImageDepth.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9339
		    bestDeviceBitsPerPixel := deviceImageBitsPerPixel.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9340
		]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9341
	    ] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9342
		"/ take the next-larger depth
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9343
		(bestDeviceDepth isNil
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9344
		 or:[deviceImageBitsPerPixel < bestDeviceBitsPerPixel]) ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9345
		    bestInfo := entry.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9346
		    bestDeviceDepth := deviceImageDepth.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9347
		    bestDeviceBitsPerPixel := deviceImageBitsPerPixel.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9348
		]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9349
	    ]    
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9350
	].
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  9351
    ].
851
c9511f8945ce fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents: 841
diff changeset
  9352
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  9353
    bestDeviceDepth isNil ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9354
	maxBitsPerPixel == 0 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9355
	    "/
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9356
	    "/ oops - nothing appropriate
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9357
	    "/
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9358
	    maxInfo notNil ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9359
		^ maxInfo
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9360
	    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9361
	    bestDeviceDepth := bestDeviceBitsPerPixel := aDevice depth.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9362
	    bestInfo := IdentityDictionary new.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9363
	    bestInfo at:#depth put:bestDeviceDepth.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9364
	    bestInfo at:#bitsPerPixel put:bestDeviceBitsPerPixel.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9365
	    bestInfo at:#padding put:32.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9366
	] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9367
	    bestInfo := maxInfo.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9368
	]
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  9369
    ].
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  9370
    ^ bestInfo
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  9371
851
c9511f8945ce fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents: 841
diff changeset
  9372
    "Modified: 14.6.1996 / 14:46:40 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9373
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9374
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9375
colormapFromImage:anImage
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9376
    "setup the receivers colormap from another image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9377
     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
  9378
     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
  9379
     for fromImage:/fromSubImake:"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9380
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9381
    samplesPerPixel == 3 ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9382
	photometric := #rgb
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9383
    ] ifFalse:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9384
	photometric := anImage photometric.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9385
	photometric == #palette ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9386
	    colorMap := anImage colorMap copy.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9387
	    "
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9388
	     must compress the colormap, if source image has higher depth
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9389
	     than myself. 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9390
	    "
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9391
	    anImage bitsPerPixel > self bitsPerPixel ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9392
		"
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9393
		 get used colors are extracted into our colorMap
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9394
		 (the at-put below will set the pixelValue according the
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9395
		 new colorIndex
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9396
		"
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9397
		colorMap := anImage usedColors asArray.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9398
		colorMap size > (1 bitShift:self bitsPerPixel) ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9399
		    'Image [warning]: possibly too many colors in image' errorPrintCR
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9400
		]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9401
	    ]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9402
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9403
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9404
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9405
    "Created: 20.9.1995 / 00:58:42 / claus"
1175
5595569cfbd3 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 1170
diff changeset
  9406
    "Modified: 10.1.1997 / 17:52:21 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9407
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9408
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9409
greyByteMapForRange:range
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9410
    "return a collection to map from pixelValues to greyLevels
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9411
     in the range 0..range. 
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9412
     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
  9413
     The values are rounded towards the nearest pixel."
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9414
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  9415
    |d clr val greyMap r
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  9416
     n "{ Class: SmallInteger }"|
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  9417
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  9418
    r := range.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  9419
    r == 256 ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9420
	r := 255
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9421
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9422
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9423
    photometric == #palette ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9424
	n := colorMap size.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9425
	greyMap := ByteArray new:n.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9426
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9427
	1 to:n do:[:i |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9428
	    (clr := colorMap at:i) isNil ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9429
		"/ an unused color
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9430
		val := 0.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9431
	    ] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9432
		val := (r * clr brightness) rounded
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9433
	    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9434
	    greyMap at:i put:val
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9435
	].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9436
    ] ifFalse:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9437
	d := self bitsPerPixel.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9438
	n := 1 bitShift:d.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9439
	n >= 4096 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9440
	    self error:'size not supported - too large'.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9441
	    ^ nil
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9442
	].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9443
	greyMap := ByteArray new:n.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9444
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9445
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9446
	photometric == #rgb ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9447
	    1 to:n do:[:i |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9448
		greyMap at:i put:(r * (self colorFromValue:i-1) brightness) rounded
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9449
	    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9450
	] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9451
	    1 to:n do:[:i |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9452
		greyMap at:i put:(r / (n-1) * (i-1)) rounded
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9453
	    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9454
	    photometric == #blackIs0 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9455
		"/ we are done
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9456
	    ] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9457
		photometric == #whiteIs0 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9458
		    greyMap reverse
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9459
		] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9460
		    self error:'invalid format'.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9461
		    ^ nil
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9462
		]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9463
	    ]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9464
	].
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9465
    ].
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  9466
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9467
    ^ greyMap
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9468
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9469
    "
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  9470
     Depth8Image new greyByteMapForRange:256
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  9471
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  9472
     Depth8Image new greyByteMapForRange:64
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  9473
     Depth4Image new greyByteMapForRange:64
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  9474
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  9475
     Depth4Image new greyByteMapForRange:1
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9476
    "
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9477
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9478
    "Created: 8.6.1996 / 08:34:14 / cg"
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  9479
    "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
  9480
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9481
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9482
greyMapForRange:range
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9483
    "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
  9484
     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
  9485
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  9486
    |d r clr val
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9487
     n "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9488
     greyArray|
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9489
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9490
    d := self bitsPerPixel.
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9491
    n := 1 bitShift:d.
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9492
    n >= 4096 ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9493
	self error:'size not supported - too large'.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9494
	^ nil
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9495
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9496
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9497
    greyArray := Array new:n.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9498
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9499
    photometric == #palette ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9500
	n := colorMap size.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9501
	1 to:n do:[:i |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9502
	    (clr := colorMap at:i) isNil ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9503
		"/ an unused color
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9504
		val := 0.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9505
	    ] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9506
		val := range * clr brightness
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9507
	    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9508
	    greyArray at:i put:val
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9509
	].
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9510
    ] ifFalse:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9511
	photometric == #rgb ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9512
	    1 to:n do:[:i |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9513
		greyArray at:i put:(range * (self colorFromValue:(i-1)) brightness)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9514
	    ]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9515
	] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9516
	    r := range asFloat.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9517
	    1 to:n do:[:i |
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9518
		greyArray at:i put:(r / (n-1) * (i-1))
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9519
	    ].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9520
	    photometric == #blackIs0 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9521
		"/ we are done
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9522
	    ] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9523
		photometric == #whiteIs0 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9524
		    greyArray reverse
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9525
		] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9526
		    self error:'invalid format'.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9527
		    ^ nil
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9528
		]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9529
	    ]
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9530
	]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9531
    ].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9532
    ^ greyArray
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9533
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9534
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9535
     Depth8Image new greyMapForRange:64
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9536
     Depth4Image new greyMapForRange:64
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9537
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9538
     Depth16Image new greyMapForRange:1
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9539
     Depth4Image new greyMapForRange:1
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9540
     Depth2Image new greyMapForRange:1
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9541
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9542
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  9543
    "Modified: 1.3.1997 / 15:48:49 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9544
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9545
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9546
magnifyRowFrom:srcBytes offset:srcStart pixels:oldPixels 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9547
	  into:dstBytes offset:dstStart factor:mX
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9548
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9549
    "magnify a single pixel row - can only magnify by integer factors,
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9550
     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
  9551
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9552
    ^ self subclassResponsibility
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  9553
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  9554
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  9555
makeDeviceGrayPixmapOn:aDevice depth:depth fromArray:bits
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  9556
    "given the bits of a grey/color bitmap, 8-bit padded and
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  9557
     pixels interpreted as greyValues, 0 is black,  
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  9558
     create a device form for it"
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  9559
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  9560
    |f|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  9561
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  9562
    f := Form width:width height:height depth:depth on:aDevice.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  9563
    f isNil ifTrue:[^ nil].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  9564
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  9565
    f bits:bits.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  9566
    f initGC.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  9567
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  9568
    (aDevice blackpixel ~~ 0) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9569
	"/ have to invert bits
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9570
	f function:#copyInverted
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  9571
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  9572
    aDevice drawBits:bits depth:depth
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9573
	       width:width height:height
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9574
		   x:0 y:0
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9575
		into:(f id) 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9576
		   x:0 y:0 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9577
	       width:width height:height 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9578
		with:(f gcId).
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  9579
    ^ f
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  9580
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  9581
    "Created: 10.6.1996 / 20:10:31 / cg"
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  9582
!
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  9583
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  9584
makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  9585
    "given the bits of a monochrome bitmap, 8-bit padded and
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  9586
     0-bits as black, create a device form for it"
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  9587
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  9588
"/    monoBits invert.
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  9589
    ^ (Form width:width height:height fromArray:monoBits on:aDevice)
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9590
	colorMap:(Array with:Color black with:Color white).
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  9591
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  9592
    "Created: 10.6.1996 / 20:18:09 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  9593
    "Modified: 17.4.1997 / 01:07:38 / cg"
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  9594
!
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  9595
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  9596
makeDevicePixmapOn:aDevice depth:depth fromArray:bits
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  9597
    "given the bits of a grey/color bitmap, 8-bit padded and
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  9598
     pixels interpreted as in the devices colormap, 
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  9599
     create a device form for it"
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  9600
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  9601
    |f|
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  9602
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  9603
    f := Form width:width height:height depth:depth on:aDevice.
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  9604
    f isNil ifTrue:[^ nil].
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  9605
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  9606
    f bits:bits.
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  9607
    f initGC.
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  9608
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  9609
    aDevice drawBits:bits depth:depth
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9610
	       width:width height:height
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9611
		   x:0 y:0
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9612
		into:(f id) 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9613
		   x:0 y:0 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9614
	       width:width height:height 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9615
		with:(f gcId).
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  9616
    ^ f
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  9617
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  9618
    "Created: 10.6.1996 / 17:56:08 / cg"
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  9619
    "Modified: 10.6.1996 / 20:11:27 / cg"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  9620
! !
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  9621
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9622
!Image methodsFor:'queries'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9623
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9624
averageColor
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9625
    "return the average color of the image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9626
     This usually only makes sense for textures and patterns
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9627
     (i.e. to compute shadow & light colors for viewBackgrounds).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9628
     Notice, that for the above purpose, it is usually ok to process 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9629
     a subImage - i.e. use Image>>averageColorIn: on a smaller rectangle"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9630
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9631
    ^ self averageColorIn:(0@0 corner:(width-1)@(height-1))
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9632
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9633
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9634
averageColorIn:aRectangle
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9635
    "return the images average color in an area.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9636
     The implementation below is slow - so you may want to
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9637
     create tuned versions for DepthXImage if you plan to do
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9638
     heavy image processing ... 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9639
     (also, creating tuned versions of the enumeration messages helps a lot)"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9640
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9641
    |x0 "{ Class:SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9642
     y0 "{ Class:SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9643
     x1 "{ Class:SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9644
     y1 "{ Class:SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9645
     sumRed sumGreen sumBlue n|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9646
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9647
    sumRed := sumGreen := sumBlue := 0.    
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9648
    y0 := aRectangle top.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9649
    y1 := aRectangle bottom.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9650
    x0 := aRectangle left.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9651
    x1 := aRectangle right.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9652
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9653
    self colorsFromX:x0 y:y0 toX:x1 y:y1 do:[:x :y :colorAtXY |
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9654
       sumRed := sumRed + colorAtXY red.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9655
       sumGreen := sumGreen + colorAtXY green.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9656
       sumBlue := sumBlue + colorAtXY blue.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9657
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9658
    n := (x1 - x0 + 1) * (y1 - y0 + 1).    
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9659
    ^ Color red:(sumRed / n) green:(sumGreen / n) blue:(sumBlue / n)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9660
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9661
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9662
bitsPerPixel
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9663
    "return the number of bits per pixel"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9664
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9665
    ^ (bitsPerSample inject:0 into:[:sum :i | sum + i])
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9666
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9667
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9668
bitsPerRow
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9669
    "return the number of bits in one scanline of the image"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9670
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9671
    ^  width * (self bitsPerPixel).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9672
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9673
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9674
blueBitsOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9675
    "if the receiver is an rgb-image:
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9676
     return the blue bits of a pixelValue.
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9677
     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
  9678
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9679
    |blueBits|
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9680
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9681
    samplesPerPixel >= 3 ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9682
	"/ assume that the red bits are the leftMost bits
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9683
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9684
	blueBits := bitsPerSample at:3.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9685
	blueBits == 0 ifTrue:[^ 0].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9686
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9687
	^ 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
  9688
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9689
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9690
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9691
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9692
    "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
  9693
    "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
  9694
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9695
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9696
blueComponentOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9697
    "if the receiver is an rgb-image:
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9698
     return the blue component (0 .. 100) of a pixelValue.
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9699
     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
  9700
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  9701
    |blueBits  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  9702
     s         "{ Class: SmallInteger }"|
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9703
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9704
    samplesPerPixel >= 3 ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9705
	"/ assume that the red bits are the leftMost bits
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9706
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9707
	blueBits := bitsPerSample at:3.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9708
	blueBits == 0 ifTrue:[^ 0].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9709
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9710
	s := (1 bitShift:blueBits) - 1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9711
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9712
	^ 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
  9713
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9714
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9715
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9716
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9717
    "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
  9718
    "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
  9719
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9720
680
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
  9721
bounds
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
  9722
    "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
  9723
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
  9724
    ^ 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
  9725
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
  9726
    "Created: 13.5.1996 / 10:27:06 / cg"
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
  9727
!
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
  9728
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9729
brightness
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9730
    "return the (average) brightness of the image.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9731
     This usually only makes sense for textures and patterns
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9732
     (i.e. to compute shadow & light colors for viewBackgrounds).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9733
     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
  9734
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9735
    ^ (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
  9736
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9737
    "Modified: 8.6.1996 / 08:46:46 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9738
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9739
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9740
bytesPerRow
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9741
    "return the number of bytes in one scanline of the image"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9742
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9743
    |bitsPerRow bytesPerRow|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9744
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9745
    bitsPerRow := width * (self bitsPerPixel).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9746
    bytesPerRow := bitsPerRow // 8.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9747
    ((bitsPerRow \\ 8) ~~ 0) ifTrue:[
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9748
	bytesPerRow := bytesPerRow + 1
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9749
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9750
    ^ bytesPerRow
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9751
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9752
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9753
colorFromValue:pixelValue
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9754
    "given a pixel value, return the corresponding color.
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9755
     Pixel values start with 0."
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9756
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
  9757
    |p maxPixel r g b|
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
  9758
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
  9759
    p := photometric.
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
  9760
    p isNil ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9761
	colorMap notNil ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9762
	    p := #palette
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9763
	] ifFalse:[
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
  9764
"/            'Image [warning]: no photometric - assume greyscale' infoPrintCR
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9765
	    p := #blackIs0
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9766
	]
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
  9767
    ].
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
  9768
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
  9769
    p == #blackIs0 ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9770
	maxPixel := (1 bitShift:self bitsPerPixel) - 1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9771
	^ Color gray:(pixelValue * (100 / maxPixel)).
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9772
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9773
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
  9774
    p == #whiteIs0 ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9775
	maxPixel := (1 bitShift:self bitsPerPixel) - 1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9776
	^ 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
  9777
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9778
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
  9779
    p == #palette ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9780
	pixelValue >= colorMap size ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9781
	    ^ Color black
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9782
	].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9783
	^ colorMap at:(pixelValue + 1)
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9784
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9785
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
  9786
    p == #rgb ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9787
	r := self redComponentOf:pixelValue.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9788
	g := self greenComponentOf:pixelValue.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9789
	b := self blueComponentOf:pixelValue.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9790
	^ Color red:r green:g blue:b
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9791
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9792
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9793
    self error:'invalid photometric'
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9794
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9795
    "Created: 8.6.1996 / 08:46:18 / cg"
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
  9796
    "Modified: 28.1.1997 / 12:05:22 / cg"
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9797
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9798
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9799
greenBitsOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9800
    "if the receiver is an rgb-image:
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9801
     return the green bits of a pixelValue.
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9802
     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
  9803
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9804
    |blueBits greenBits|
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9805
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9806
    samplesPerPixel >= 3 ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9807
	"/ assume that the red bits are the leftMost bits
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9808
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9809
	greenBits := bitsPerSample at:2.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9810
	greenBits == 0 ifTrue:[^ 0].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9811
	blueBits := bitsPerSample at:3.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9812
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9813
	^ (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
  9814
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9815
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9816
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9817
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9818
    "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
  9819
    "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
  9820
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9821
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9822
greenComponentOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9823
    "if the receiver is an rgb-image:
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9824
     return the green component (0..100)  of a pixelValue.
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9825
     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
  9826
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  9827
    |greenBits "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  9828
     blueBits  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  9829
     s         "{ Class: SmallInteger }"|
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9830
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9831
    samplesPerPixel >= 3 ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9832
	"/ assume that the red bits are the leftMost bits
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9833
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9834
	greenBits := bitsPerSample at:2.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9835
	greenBits == 0 ifTrue:[^ 0].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9836
	blueBits := bitsPerSample at:3.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9837
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9838
	s := (1 bitShift:greenBits) - 1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9839
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9840
	^ 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
  9841
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9842
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9843
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9844
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9845
    "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
  9846
    "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
  9847
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9848
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  9849
heightOn:aGC
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  9850
    "return my height, if displayed on aGC;
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  9851
     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
  9852
     return the pixel-height"
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  9853
680
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
  9854
    ^ height
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  9855
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  9856
    "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
  9857
    "Modified: 13.5.1996 / 10:26:36 / cg"
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  9858
!
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  9859
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9860
isImage
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9861
    "return true, if the receiver is some kind of image;
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9862
     true is returned here - the method is redefined from Object."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9863
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9864
    ^ true
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9865
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9866
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9867
isImageOrForm
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9868
    "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
  9869
     true is returned here - the method is redefined from Object."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9870
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9871
    ^ true
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9872
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9873
1630
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  9874
isMask
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  9875
    ^ false
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  9876
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  9877
    "Created: 22.4.1997 / 14:12:02 / cg"
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  9878
!
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  9879
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  9880
pixelArraySpecies
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  9881
    "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
  9882
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9883
    self depth > 8 ifTrue:[
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9884
        ^ Array
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  9885
    ].
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  9886
    ^ ByteArray
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  9887
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  9888
    "Created: 6.3.1997 / 15:24:05 / cg"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9889
    "Modified: 24.4.1997 / 15:34:34 / cg"
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  9890
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  9891
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  9892
realColorMap
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  9893
    "return a collection usable as a real colormap of the image.
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  9894
     For palette images, this is the internal colormap; 
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  9895
     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
  9896
     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
  9897
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  9898
    |d nEntries "{ Class: SmallInteger }"
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  9899
     colorArray|
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  9900
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  9901
    photometric == #palette ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9902
	^ colorMap asArray
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  9903
    ].
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  9904
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  9905
    d := self depth.
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  9906
    d > 12 ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9907
	self error:'deep palette images not supported'.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9908
	^ nil.
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  9909
    ].
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  9910
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  9911
    nEntries := 1 bitShift:d.
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  9912
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  9913
    colorArray := Array new:nEntries.
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  9914
    1 to:nEntries do:[:idx |
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9915
	colorArray at:idx put:(self colorFromValue:(idx-1)).
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  9916
    ].
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  9917
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  9918
    ^ colorArray
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  9919
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  9920
    "Created: 11.7.1996 / 20:20:35 / cg"
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  9921
    "Modified: 11.7.1996 / 20:49:21 / cg"
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  9922
!
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  9923
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9924
redBitsOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9925
    "if the receiver is an rgb-image:
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9926
     return the red component of a pixelValue.
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9927
     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
  9928
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9929
    |redBits greenBits blueBits|
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9930
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9931
    samplesPerPixel >= 3 ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9932
	"/ assume that the red bits are the leftMost bits
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9933
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9934
	redBits := bitsPerSample at:1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9935
	redBits == 0 ifTrue:[^ 0].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9936
	greenBits := bitsPerSample at:2.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9937
	blueBits := bitsPerSample at:3.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9938
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9939
	^ (pixel bitShift:(greenBits + blueBits) negated)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9940
	   bitAnd:(1 bitShift:redBits)-1
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9941
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9942
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9943
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9944
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9945
    "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
  9946
    "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
  9947
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9948
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9949
redComponentOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9950
    "if the receiver is an rgb-image:
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9951
     return the red component (0..100) of a pixelValue.
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9952
     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
  9953
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  9954
    |redBits   "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  9955
     greenBits "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  9956
     blueBits  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  9957
     s         "{ Class: SmallInteger }"|
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9958
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9959
    samplesPerPixel >= 3 ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9960
	"/ assume that the red bits are the leftMost bits
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9961
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9962
	redBits := bitsPerSample at:1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9963
	redBits == 0 ifTrue:[^ 0].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9964
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9965
	greenBits := bitsPerSample at:2.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9966
	blueBits := bitsPerSample at:3.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9967
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9968
	s := (1 bitShift:redBits) - 1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9969
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9970
	^ 100.0 / s * 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9971
	  ((pixel bitShift:(greenBits + blueBits) negated)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9972
	   bitAnd:(1 bitShift:redBits)-1)
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9973
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9974
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9975
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9976
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9977
    "Created: 8.6.1996 / 08:45:30 / cg"
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  9978
    "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
  9979
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9980
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9981
usedColors
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9982
    "return a collection of colors used in the receiver."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9983
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9984
    |usedValues max|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9985
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9986
    photometric == #rgb ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9987
	"/ too many to be returned here (think of the mass of
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9988
	"/ data to be returned by a 24bit image ... ;-)
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9989
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9990
	self error:'query not allowed for this image'.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9991
	^ nil
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9992
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9993
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9994
    usedValues := self usedValues asArray.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9995
    photometric == #palette ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9996
	^ usedValues collect:[:val | (colorMap at:val+1)]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9997
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9998
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  9999
    "/ (photometric == #blackIs0 or:[photometric == #whiteIs0])
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 10000
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 10001
    max := (1 bitShift:self depth) - 1.
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 10002
    ^ usedValues collect:[:val | (Color gray:(100 * val / max ))]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10003
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10004
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10005
     (Image fromFile:'bitmaps/garfield.gif') usedColors
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10006
     (Image fromFile:'bitmaps/SBrowser.xbm') usedColors
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10007
     (Image fromFile:'ttt.tiff') usedColors  
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10008
    "
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
 10009
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 10010
    "Modified: 8.6.1996 / 09:04:56 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10011
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10012
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10013
usedValues
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10014
    "return a collection of color values used in the receiver.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10015
     Notice, that the interpretation of the pixels depends on the photometric
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10016
     of the image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10017
     This is a general and therefore slow implementation; subclasses
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10018
     may want to redefine this method for more performance."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10019
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10020
    |set|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10021
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10022
    set := IdentitySet new.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10023
    self valuesFromX:0 y:0 toX:(self width-1) y:(self height-1) do:[:x :y :pixel |
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10024
	set add:pixel 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10025
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10026
    ^ set
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10027
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10028
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10029
     (Image fromFile:'bitmaps/garfield.gif') usedValues
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10030
     (Image fromFile:'bitmaps/SBrowser.xbm') usedValues
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10031
     (Image fromFile:'ttt.tiff') usedValues  
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10032
    "
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 10033
!
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 10034
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 10035
valueFromColor:color
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 10036
    "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
 10037
     Non-representable colors return nil."
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 10038
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 10039
    |pixel maxPixel redBits greenBits blueBits r g b|
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 10040
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 10041
    photometric == #whiteIs0 ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10042
	maxPixel := (1 bitShift:self bitsPerPixel) - 1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10043
	^ maxPixel - (color brightness * maxPixel) rounded.
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 10044
    ].
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 10045
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 10046
    photometric == #blackIs0 ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10047
	maxPixel := (1 bitShift:self bitsPerPixel) - 1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10048
	^ (color brightness * maxPixel) rounded.
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 10049
    ].
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 10050
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 10051
    photometric == #palette ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10052
	pixel := colorMap indexOf:color.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10053
	pixel == 0 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10054
	    "
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10055
	     the color to be stored is not in the images colormap
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10056
	    "
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10057
	    ^ nil
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10058
	].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10059
	^ pixel - 1
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 10060
    ].
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 10061
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 10062
    photometric == #rgb ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10063
	samplesPerPixel >= 3 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10064
	    redBits := bitsPerSample at:1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10065
	    greenBits := bitsPerSample at:2.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10066
	    blueBits := bitsPerSample at:3.
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 10067
        
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10068
	    "/ map r/g/b to 0..255
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10069
	    r := (color red / 100.0 * ((1 bitShift:redBits)-1)) rounded.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10070
	    g := (color green / 100.0 * ((1 bitShift:greenBits)-1)) rounded.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10071
	    b := (color blue / 100.0 * ((1 bitShift:blueBits)-1)) rounded.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10072
	    pixel := (((r bitShift:greenBits) + g) bitShift:blueBits) + b.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10073
	    ^ pixel
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10074
	]
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 10075
    ].
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 10076
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 10077
    self error:'format not supported'.
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 10078
    ^ nil
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 10079
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 10080
    "Modified: 15.6.1996 / 09:38:09 / cg"
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 10081
!
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 10082
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 10083
widthOn:aGC
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 10084
    "return my width, if displayed on aGC;
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 10085
     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
 10086
     return the pixel-width"
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 10087
680
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 10088
    ^ width
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 10089
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 10090
    "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
 10091
    "Modified: 13.5.1996 / 10:26:42 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10092
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10093
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10094
!Image methodsFor:'saving on file'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10095
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10096
saveOn:aFileName
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10097
    "save the image in a aFileName. The suffix of the filename
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10098
     controls the format. Currently, not all formats may be supported
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 10099
     (see ImageReader subclasses implementing save:onFile:).
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 10100
     May raise a signal, if the image cannot be written by the
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 10101
     reader."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10102
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 10103
    |suffix readerClass|
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 10104
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 10105
    "/
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 10106
    "/ from the extension, get the imageReader class
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 10107
    "/ (which should know how to write images as well)
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 10108
    "/
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 10109
    suffix := aFileName asFilename suffix.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 10110
    readerClass := FileFormats at:suffix ifAbsent:nil.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 10111
    readerClass notNil ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10112
	^ self saveOn:aFileName using:readerClass
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 10113
    ].
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 10114
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 10115
    "/
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 10116
    "/ no known extension - could ask user for the format here.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 10117
    "/ currently default to tiff format.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 10118
    "/
1175
5595569cfbd3 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 1170
diff changeset
 10119
    'Image [warning]: unknown extension - cannot figure out format - using tiff' errorPrintCR.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 10120
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10121
    ^ self saveOn:aFileName using:TIFFReader
1175
5595569cfbd3 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 1170
diff changeset
 10122
1385
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 10123
    "
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 10124
     |image|
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 10125
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 10126
     image := Image fromFile:'bitmaps/RCube.tiff'.
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 10127
     image saveOn:'myImage.tiff'.
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 10128
     image saveOn:'myImage.xbm'.
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 10129
     image saveOn:'myImage.xpm'.
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 10130
     image saveOn:'myImage.xwd'.
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 10131
    "
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 10132
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 10133
    "Modified: 10.4.1997 / 17:38:35 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10134
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10135
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10136
saveOn:aFileName using:readerClass
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 10137
    "save the receiver using the representation class.
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 10138
     May raise a signal, if the image cannot be written by the
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 10139
     reader."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10140
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 10141
    ^ readerClass save:self onFile:aFileName
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10142
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10143
    "
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 10144
     |anImage|
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 10145
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 10146
     anImage := Image fromFile:'bitmaps/gifImages/garfield.gif'.
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 10147
     anImage saveOn:'myImage.tiff' using:TIFFReader.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 10148
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 10149
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 10150
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 10151
     |anImage|
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 10152
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 10153
     anImage := Image fromFile:'bitmaps/gifImages/garfield.gif'.
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 10154
     anImage saveOn:'myImage.xbm' using:XBMReader.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 10155
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 10156
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 10157
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 10158
     |anImage|
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 10159
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 10160
     anImage := Image fromFile:'bitmaps/gifImages/garfield.gif'.
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 10161
     Image cannotRepresentImageSignal handle:[:ex |
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10162
	self warn:'cannot save the image in this format'
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 10163
     ] do:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10164
	anImage saveOn:'myImage.xbm' using:XBMReader.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 10165
     ]
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 10166
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 10167
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 10168
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 10169
     |anImage|
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 10170
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 10171
     anImage := Image fromFile:'bitmaps/gifImages/garfield.gif'.
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 10172
     anImage saveOn:'myImage.xpm' using:XPMReader.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 10173
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 10174
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 10175
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 10176
     |anImage|
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 10177
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 10178
     anImage := Image fromFile:'bitmaps/gifImages/garfield.gif'.
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 10179
     anImage saveOn:'myImage.gif' using:GIFReader.
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 10180
    "
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 10181
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 10182
    "Modified: 10.4.1997 / 17:49:26 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 10183
! !
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10184
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10185
!Image methodsFor:'screen capture'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10186
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 10187
from:aDrawable in:aRectangle
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 10188
    "read an image from aDrawable.
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 10189
     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
 10190
     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
 10191
     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
 10192
     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
 10193
     and to read hardcopy images from the screen."
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
    |depth visType 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10196
     x        "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10197
     y        "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10198
     w        "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10199
     h        "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10200
     dstIndex "{ Class: SmallInteger }" 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10201
     srcIndex "{ Class: SmallInteger }" 
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 10202
     srcRow   "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 10203
     dstRow   "{ Class: SmallInteger }"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10204
     inData tmpData usedPixels mapSize 
1644
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10205
     map bitsPerPixel bytesPerLine 
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10206
     byteOrder bitOrder spaceBitsPerPixel
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 10207
     info bitsPerPixelIn bytesPerLineIn 
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 10208
     maskR "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 10209
     maskG "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 10210
     maskB "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 10211
     shR "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 10212
     shG "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 10213
     shB "{ Class: SmallInteger }"
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
 10214
     shR2 "{ Class: SmallInteger }"
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
 10215
     shG2 "{ Class: SmallInteger }"
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
 10216
     shB2 "{ Class: SmallInteger }"
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 10217
     r "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 10218
     g "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 10219
     b "{ Class: SmallInteger }"
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 10220
     word device|
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 10221
927
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 924
diff changeset
 10222
    device := aDrawable graphicsDevice.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10223
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10224
    (aDrawable isForm and:[aDrawable depth == 1]) ifTrue:[
1644
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10225
        "/ a monochrome bitmap ?
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10226
        visType := #StaticGray.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10227
        depth := 1.
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10228
    ] ifFalse:[
1644
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10229
        "
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10230
         get some attributes of the display device
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10231
        "
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10232
        visType := device visualType.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10233
        depth := device depth.
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10234
    ].
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 10235
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 10236
    "/ kludge for 15bit XFree server
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 10237
    depth == 15 ifTrue:[
1644
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10238
        depth := 16
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 10239
    ].
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 10240
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10241
    (visType == #StaticGray) ifTrue:[
1644
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10242
        (device blackpixel == 0) ifTrue:[
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10243
            photometric := #blackIs0
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10244
        ] ifFalse:[
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10245
            photometric := #whiteIs0
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10246
        ].
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10247
        samplesPerPixel := 1.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10248
        bitsPerPixel := depth.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10249
        bitsPerSample := Array with:bitsPerPixel.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10250
    ] ifFalse:[
1644
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10251
        ((visType == #PseudoColor) or:[(visType == #StaticColor) or:[visType == #GrayScale]]) ifTrue:[
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10252
            photometric := #palette.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10253
            samplesPerPixel := 1.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10254
            bitsPerPixel := depth.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10255
            bitsPerSample := Array with:bitsPerPixel.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10256
        ] ifFalse:[
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10257
            ((visType == #TrueColor) or:[visType == #DirectColor]) ifTrue:[
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10258
                photometric := #rgb.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10259
                samplesPerPixel := 3.
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
 10260
"/                bitsPerPixel := depth.
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 10261
"/                bitsPerSample := Array with:device bitsRed
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 10262
"/                                       with:device bitsGreen
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 10263
"/                                       with:device bitsBlue
1644
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10264
                bitsPerPixel := 24.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10265
                bitsPerSample := #(8 8 8).
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10266
            ] ifFalse:[
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10267
                self error:'screen visual not supported'.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10268
                ^ nil
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10269
            ]
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10270
        ]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10271
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10272
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10273
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10274
     dont know yet, how the display pads; assume worst case, 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10275
     offering enough space for 32 bit padding
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10276
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10277
    w := width := aRectangle width.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10278
    h := height := aRectangle height.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10279
    x := aRectangle left.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10280
    y := aRectangle top.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10281
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 10282
    "
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 10283
     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
 10284
     (its too late when info is present ...)
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 10285
    "
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 10286
    spaceBitsPerPixel := bitsPerPixel.
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 10287
    (bitsPerPixel > 8) ifTrue:[
1644
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10288
        spaceBitsPerPixel := 16.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10289
        (bitsPerPixel > 16) ifTrue:[
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10290
            spaceBitsPerPixel := 32.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10291
            (bitsPerPixel > 32) ifTrue:[
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10292
                spaceBitsPerPixel := bitsPerPixel.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10293
            ]
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10294
        ]
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 10295
    ].
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 10296
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 10297
    bytesPerLine := (w * spaceBitsPerPixel + 31) // 32 * 4.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10298
    inData := ByteArray uninitializedNew:(bytesPerLine * height).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10299
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10300
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10301
     get the pixels
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10302
    "
1459
84e80b355553 splitted getBitsFrom into getBitsFromPixmap
Claus Gittinger <cg@exept.de>
parents: 1446
diff changeset
 10303
    aDrawable isForm ifTrue:[
1644
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10304
        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
 10305
    ] ifFalse:[
1644
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10306
        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
 10307
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10308
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10309
    "
396
d088e672be8a handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents: 394
diff changeset
 10310
     check if byteorder is what I like (msbFirst)
d088e672be8a handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents: 394
diff changeset
 10311
    "
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 10312
    byteOrder := info at:#byteOrder.
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 10313
    bitsPerPixelIn := info at:#bitsPerPixel.
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 10314
    byteOrder ~~ #msbFirst ifTrue:[
1644
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10315
        bitsPerPixelIn == 16 ifTrue:[
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10316
            "/ must swap bytes
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10317
            inData swapBytes
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10318
        ] ifFalse:[
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10319
            bitsPerPixelIn == 32 ifTrue:[
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10320
                "/ must swap longs
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10321
                inData swapLongs
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10322
            ]
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10323
        ]
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10324
    ].
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10325
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10326
    "
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10327
     check if bitorder is what I like (msbFirst)
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10328
    "
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10329
    bitOrder := info at:#bitOrder.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10330
    bitOrder ~~ #msbFirst ifTrue:[
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10331
        inData 
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10332
            expandPixels:8 
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10333
            width:(inData size)
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10334
            height:1 
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10335
            into:inData
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10336
            mapping:(ImageReader reverseBits).
396
d088e672be8a handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents: 394
diff changeset
 10337
    ].
d088e672be8a handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents: 394
diff changeset
 10338
d088e672be8a handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents: 394
diff changeset
 10339
    "
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10340
     check, if the devices padding is different ..
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 10341
     or if the bitsPerPixels are different
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10342
    "
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 10343
    bytesPerLineIn := (info at:#bytesPerLine).                    "what I got"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10344
    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
 10345
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 10346
    ((bytesPerLine ~~ bytesPerLineIn) 
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 10347
    or:[bitsPerPixelIn ~~ bitsPerPixel]) ifTrue:[
1644
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10348
        tmpData := inData.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10349
        inData := ByteArray uninitializedNew:(bytesPerLine * height).
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10350
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10351
        srcRow := 1.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10352
        dstRow := 1.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10353
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10354
        bitsPerPixelIn ~~ bitsPerPixel ifTrue:[
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10355
            "/ for now, only 32 -> 24 is supported
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10356
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10357
            maskR := (1 bitShift:device bitsRed) - 1.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10358
            maskG := (1 bitShift:device bitsGreen) - 1.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10359
            maskB := (1 bitShift:device bitsBlue) - 1.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10360
            shR := device shiftRed negated.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10361
            shG := device shiftGreen negated.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10362
            shB := device shiftBlue negated.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10363
            shR2 := (8 - device bitsRed).
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10364
            shG2 := (8 - device bitsGreen).
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10365
            shB2 := (8 - device bitsBlue).
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10366
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10367
            ((bitsPerPixelIn == 32) and:[bitsPerPixel == 24]) ifTrue:[
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10368
                "/ 'reformatting 32->24...' printNL.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10369
                1 to:h do:[:hi |
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10370
                    srcIndex := srcRow.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10371
                    dstIndex := dstRow.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10372
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10373
                    1 to:w do:[:wi |
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10374
                        word := tmpData doubleWordAt:srcIndex MSB:true.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10375
                        r := (word bitShift:shR) bitAnd:maskR.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10376
                        g := (word bitShift:shG) bitAnd:maskG.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10377
                        b := (word bitShift:shB) bitAnd:maskB.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10378
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10379
                        inData at:dstIndex   put:r.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10380
                        inData at:dstIndex+1 put:g.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10381
                        inData at:dstIndex+2 put:b.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10382
                        srcIndex := srcIndex + 4.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10383
                        dstIndex := dstIndex + 3.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10384
                    ].
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10385
                    dstRow := dstRow + bytesPerLine.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10386
                    srcRow := srcRow + bytesPerLineIn
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10387
                ]
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10388
            ] ifFalse:[
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10389
                ((bitsPerPixelIn == 16) and:[bitsPerPixel == 24]) ifTrue:[
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10390
                    "/ 'reformatting 16->24...' printNL.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10391
                    1 to:h do:[:hi |
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10392
                        srcIndex := srcRow.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10393
                        dstIndex := dstRow.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10394
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10395
                        1 to:w do:[:wi |
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10396
                            word := tmpData wordAt:srcIndex MSB:true.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10397
                            r := (word bitShift:shR) bitAnd:maskR.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10398
                            g := (word bitShift:shG) bitAnd:maskG.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10399
                            b := (word bitShift:shB) bitAnd:maskB.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10400
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10401
                            inData at:dstIndex   put:(r bitShift:shR2).
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10402
                            inData at:dstIndex+1 put:(g bitShift:shG2).
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10403
                            inData at:dstIndex+2 put:(b bitShift:shB2).
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10404
                            srcIndex := srcIndex + 2.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10405
                            dstIndex := dstIndex + 3.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10406
                        ].
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10407
                        dstRow := dstRow + bytesPerLine.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10408
                        srcRow := srcRow + bytesPerLineIn
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10409
                    ]
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10410
                ] ifFalse:[
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10411
                    ('Image [warning]: unsupported depth combination: ' , bitsPerPixelIn printString , ' -> ' ,
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10412
                                                        bitsPerPixel printString) errorPrintCR.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10413
                    ^ nil
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10414
                ]
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10415
            ].
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10416
        ] ifFalse:[
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10417
            "
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10418
             repad in the buffer
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10419
            "
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10420
            1 to:h do:[:hi |
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10421
                inData replaceFrom:dstRow to:(dstRow + bytesPerLine - 1)
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10422
                              with:tmpData startingAt:srcRow.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10423
                dstRow := dstRow + bytesPerLine.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10424
                srcRow := srcRow + bytesPerLineIn
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10425
            ]
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10426
        ]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10427
    ] ifFalse:[
1644
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10428
        (bytesPerLine * height) ~~ inData size ifTrue:[
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10429
            tmpData := inData.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10430
            inData := ByteArray uninitializedNew:(bytesPerLine * height).
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10431
            inData replaceFrom:1 to:bytesPerLine * height with:tmpData startingAt:1
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10432
        ]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10433
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10434
    bytes := inData.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10435
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10436
    "info printNL."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10437
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 10438
    ((visType == #StaticGray) 
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 10439
    or:[visType == #TrueColor
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 10440
    or:[visType == #DirectColor]]) ifTrue:[
1644
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10441
        "
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10442
         were done, the pixel values are the rgb/grey values
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10443
        "
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10444
    ] ifFalse:[
1644
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10445
        "
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10446
         what we have now are the color numbers - still need the r/g/b values.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10447
         find out, which colors are in the picture
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10448
        "
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10449
        usedPixels := inData usedValues.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10450
        mapSize := usedPixels max + 1.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10451
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10452
        "get the palette"
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10453
        map := Array new:mapSize.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10454
        usedPixels do:[:colorIndex |
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10455
            |i|
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10456
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10457
            i := colorIndex + 1.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10458
            device getRGBFrom:colorIndex into:[:r :g :b |
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10459
                map at:i put:(Color red:r green:g blue:b)
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10460
            ]
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10461
        ].
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10462
        colorMap := map.
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10463
    ].
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10464
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 10465
    "Modified: 23.4.1997 / 14:16:19 / cg"
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 10466
!
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 10467
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 10468
fromScreen:aRectangle
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 10469
    "read an image from the display screen.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 10470
     WARNING: this temporarily grabs the display
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10471
	      it may not work from within a buttonMotion
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10472
	      (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
 10473
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 10474
    ^ self 
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10475
	fromScreen:aRectangle 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10476
	on:Screen current
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10477
	grab:true
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 10478
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 10479
    "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
 10480
!
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 10481
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 10482
fromScreen:aRectangle on:aDevice
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 10483
    "read an image from aDevices display screen.
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 10484
     Since I have no other displays, only the MonoChrome, StaticGrey 
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 10485
     and PseudoColor cases have been tested ... 
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 10486
     (especially True- and DirectColor may be wrong).
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 10487
     Late note: 24bit rgb now also works.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 10488
     WARNING: this temporarily grabs the display
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10489
              it may not work from within a buttonMotion
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10490
              (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
 10491
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 10492
    ^ self
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10493
        fromScreen:aRectangle 
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10494
        on:aDevice 
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10495
        grab:true
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10496
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10497
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10498
     Image fromScreen:((0 @ 0) corner:(100 @ 100)) on:Display
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10499
     Image fromScreen:((0 @ 0) corner:(500 @ 500)) on:Display
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10500
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10501
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10502
    "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
 10503
!
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 10504
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 10505
fromScreen:aRectangle on:aDevice grab:doGrab
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 10506
    "read an image from aDevices display screen.
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 10507
     If the doGrab argument is true, the display
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 10508
     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
 10509
     shown while the readout is done.
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 10510
     Since I have no other displays, only the MonoChrome, StaticGrey 
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 10511
     and PseudoColor cases have been tested ... 
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 10512
     (especially True- and DirectColor may be wrong).
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 10513
     Late note: 24bit rgb now also works.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 10514
     WARNING: with doGrab true, this temporarily grabs the display
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10515
	      and it may not work from within a buttonMotion
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10516
	      (use with a false grabArg then)."
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 10517
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 10518
    |curs cid rootView|
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 10519
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 10520
    doGrab ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10521
	curs := Cursor sourceForm:(Image fromFile:'bitmaps/Camera.xbm')
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10522
			 maskForm:(Image fromFile:'bitmaps/Camera_m.xbm')
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10523
			  hotSpot:16@16.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10524
	curs notNil ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10525
	    cid := (curs on:aDevice) id
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10526
	].
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 10527
    ].
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 10528
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 10529
    "
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 10530
     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
 10531
    "
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 10532
    rootView := aDevice rootView.
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 10533
    doGrab ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10534
	aDevice setActivePointerGrab:rootView.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10535
	aDevice grabPointerIn:rootView id
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10536
		   withCursor:cid 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10537
		   pointerMode:#async 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10538
		   keyboardMode:#sync 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10539
		   confineTo:nil.
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 10540
    ].
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 10541
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 10542
    "
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 10543
     get the pixels
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 10544
    "
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 10545
    [
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10546
	self from:rootView in:aRectangle.
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 10547
    ] valueNowOrOnUnwindDo:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10548
	doGrab ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10549
	    aDevice ungrabPointer.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10550
	]
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 10551
    ]
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 10552
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 10553
    "Created: 26.3.1997 / 10:36:30 / cg"
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 10554
    "Modified: 26.3.1997 / 10:44:45 / cg"
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10555
!
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10556
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10557
photometricFromScreen:aDevice
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10558
    "read aDevices display photometric and set my colormap for it.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10559
     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
 10560
     or from an offScreen bitmap, for correct pixel interpretation."
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10561
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10562
    |depth visType bitsPerPixel|
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10563
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10564
    "
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10565
     get some attributes of the display device
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10566
    "
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10567
    visType := aDevice visualType.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10568
    depth := aDevice depth.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10569
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10570
    "/ kludge for 15bit XFree server
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10571
    depth == 15 ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10572
	depth := 16
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10573
    ].
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10574
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10575
    (visType == #StaticGray) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10576
	(aDevice blackpixel == 0) ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10577
	    photometric := #blackIs0
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10578
	] ifFalse:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10579
	    photometric := #whiteIs0
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10580
	].
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10581
	samplesPerPixel := 1.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10582
	bitsPerPixel := depth.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10583
	bitsPerSample := Array with:bitsPerPixel.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10584
	"
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10585
	 were done, the pixel values are the grey values
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10586
	"
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10587
	^ self
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10588
    ].
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10589
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10590
    ((visType == #TrueColor) or:[visType == #DirectColor]) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10591
	photometric := #rgb.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10592
	samplesPerPixel := 3.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10593
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10594
	"/ for now - only support 24bit TrueColor
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10595
	depth ~~ 24 ifTrue:[
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10596
	    'IMAGE: unsupported display depth' errorPrintCR.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10597
	].
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10598
"/                bitsPerPixel := depth.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10599
"/                bitsPerSample := Array with:aDevice bitsRed
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10600
"/                                       with:aDevice bitsGreen
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10601
"/                                       with:aDevice bitsBlue
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10602
	bitsPerPixel := 24.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10603
	bitsPerSample := #(8 8 8).
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10604
	"
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10605
	 were done, the pixel values are the rgb values
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10606
	"
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10607
	^ self
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10608
    ].
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10609
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10610
    ((visType ~~ #PseudoColor) 
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10611
    and:[(visType ~~ #StaticColor) 
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10612
    and:[visType ~~ #GrayScale]]) ifTrue:[
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10613
	self error:'screen visual not supported'.
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10614
	^ nil
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10615
    ].
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10616
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10617
    photometric := #palette.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10618
    samplesPerPixel := 1.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10619
    bitsPerPixel := depth.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10620
    bitsPerSample := Array with:bitsPerPixel.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10621
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10622
    "
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10623
     still need the pixels r/g/b values ...
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10624
    "
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10625
    colorMap := aDevice colorMap
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10626
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 10627
    "Modified: 11.7.1996 / 11:11:34 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10628
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10629
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
 10630
!Image class methodsFor:'documentation'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10631
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10632
version
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
 10633
    ^ '$Header: /cvs/stx/stx/libview/Image.st,v 1.191 1997-04-24 21:13:56 cg Exp $'
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
 10634
! !
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10635
Image initialize!