Image.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Tue, 03 Oct 2017 11:38:15 +0100
branchjv
changeset 8188 00df122d8bd4
parent 8080 0e9dfadee86c
child 8271 8599cc6c703d
permissions -rw-r--r--
X11: backed out changeset 03ebf4f9a91d This is no good, it completely trashes copy-paste on X11.
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
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
     3
              All Rights Reserved
0
48194c26a46c Initial revision
claus
parents:
diff changeset
     4
48194c26a46c Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
48194c26a46c Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
48194c26a46c Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
48194c26a46c Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
48194c26a46c Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
48194c26a46c Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
48194c26a46c Initial revision
claus
parents:
diff changeset
    11
"
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
    12
"{ Package: 'stx:libview' }"
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
    13
6755
cee1206f74db class: Image
Claus Gittinger <cg@exept.de>
parents: 6653
diff changeset
    14
"{ NameSpace: Smalltalk }"
cee1206f74db class: Image
Claus Gittinger <cg@exept.de>
parents: 6653
diff changeset
    15
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    16
Object subclass:#Image
7529
5f77a718b7bd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7523
diff changeset
    17
	instanceVariableNames:'pixelFunction bytes width height bitsPerPixel depth colorMap
5f77a718b7bd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7523
diff changeset
    18
		maxPixelValue rowByteSize bitsPerSample samplesPerPixel
5f77a718b7bd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7523
diff changeset
    19
		photometric device deviceForm monoDeviceForm fullColorDeviceForm
5f77a718b7bd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7523
diff changeset
    20
		mask maskedPixelsAre0 fileName imageSequence metaData'
5f77a718b7bd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7523
diff changeset
    21
	classVariableNames:'Lobby DitherAlgorithm NumberOfDitherColors
5f77a718b7bd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7523
diff changeset
    22
		CollectGarbageWhenRunningOutOfColors ImageErrorSignal
5f77a718b7bd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7523
diff changeset
    23
		ImageNotFoundQuerySignal BadImageFormatQuerySignal
5f77a718b7bd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7523
diff changeset
    24
		ImageSaveErrorSignal ImageLoadErrorSignal FileCreationErrorSignal
5f77a718b7bd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7523
diff changeset
    25
		CannotRepresentImageSignal InformationLostQuerySignal
7170
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
    26
		UnrepresentableColorSignal ARGB_A_OFFSET_MACHINE
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
    27
		ARGB_R_OFFSET_MACHINE ARGB_G_OFFSET_MACHINE ARGB_B_OFFSET_MACHINE'
7529
5f77a718b7bd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7523
diff changeset
    28
	poolDictionaries:''
5f77a718b7bd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7523
diff changeset
    29
	category:'Graphics-Images'
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    30
!
48194c26a46c Initial revision
claus
parents:
diff changeset
    31
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
    32
!Image class methodsFor:'documentation'!
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    33
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    34
copyright
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    35
"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    36
 COPYRIGHT (c) 1991 by Claus Gittinger
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
    37
              All Rights Reserved
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    38
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    39
 This software is furnished under a license and may be used
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    40
 only in accordance with the terms of that license and with the
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    41
 inclusion of the above copyright notice.   This software may not
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    42
 be provided or otherwise made available to, or used by, any
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    43
 other person.  No title to or ownership of the software is
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    44
 hereby transferred.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    45
"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    46
!
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    47
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    48
documentation
48194c26a46c Initial revision
claus
parents:
diff changeset
    49
"
6284
ebd0dfb1322c cleanup - removed unused instvars
Claus Gittinger <cg@exept.de>
parents: 6256
diff changeset
    50
    this class provides representation for all kinds of images
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
    51
    (monochrome, greyscale and color) and may finally replace Form.
6166
87e576aea243 class: Image
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
    52
    Depths of 1, 2, 4, 8, 16, 24 and 32 are supported.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    53
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    54
    An Image keeps all of its information in a device independent way,
6166
87e576aea243 class: Image
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
    55
    but may be associated to a device (i.e. getting a device-specific version of it).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    56
    The data held keeps all information which was originally present,
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    57
    even if the display-device has lower resolution.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    58
    Therefore, it is possible to process and manipulate images without loosing
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    59
    color information.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    60
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    61
    Images may be created manually (by providing a pixel array),
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
    62
    by screen capture, by reading a file (using an ImageReader) or
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
    63
    dynamically computed by a pixelFunction (functional image).
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
    64
6166
87e576aea243 class: Image
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
    65
    This gives you a device independent image.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    66
    For display, a device representation is required, which can be
7404
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
    67
    acquired by sending the 'onDevice:aDevice' message to the image.
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
    68
    This creates a (possibly dithered) device-form,
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    69
    representing the image using the currently available colors.
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    70
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    71
    In rare cases, an explicit monochrome representation of the image is needed
6166
87e576aea243 class: Image
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
    72
    (some older X servers take monochrome icons only), this can be created by sending
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    73
    it the message
7404
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
    74
        'monochromeOn:aDevice'.
6284
ebd0dfb1322c cleanup - removed unused instvars
Claus Gittinger <cg@exept.de>
parents: 6256
diff changeset
    75
ebd0dfb1322c cleanup - removed unused instvars
Claus Gittinger <cg@exept.de>
parents: 6256
diff changeset
    76
    As this class is very old and originated at times when typical graphic diplays only
6166
87e576aea243 class: Image
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
    77
    supported a limited number of colors (16 or 256), you will find a lot of code which deals
87e576aea243 class: Image
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
    78
    with color allocation optimizations and dithering. Nowadays, these are hardly ever needed,
87e576aea243 class: Image
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
    79
    and most of the time, images will be converted to 24bit truecolor (8x8x8) when converted
87e576aea243 class: Image
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
    80
    to a device representation.
286
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    81
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    82
    An images pixel interpretation is controlled by the photometric instance variable
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    83
    and (if that is #palette) a colorMap.
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    84
    This is in contrast to the ST-80 way, where all of this info is in the colorMap
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    85
    (and using specialized colorMaps for b&w / greyScale images).
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    86
    This may change in future versions for more application compatibility.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    87
286
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    88
    To convert pictures from/to external file-formats, image readers are used
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    89
    which have the file-format knowledge built in.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    90
    There are readers for most common formats available
286
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    91
    (see ImageReader and especially subclasses such as TIFFReader, GIFReader etc.).
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    92
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    93
    File formats are handled by subclasses of ImageReader, which understand
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    94
    a specific format. You can add more readers, by adding an association
6166
87e576aea243 class: Image
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
    95
    to the mapping maintained in the MIMETypes class.
87e576aea243 class: Image
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
    96
    (see the MIMETypes>>initialize and possibly the display.rc file, where this is done).
286
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    97
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    98
    Some algorithms used here (especially dithering & color allocation) are
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    99
    experimental and far from being perfect (some are very slow).
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   100
    For now, the most common cases have been optimized and perform reasonably
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   101
    fast - however, with uncommon depth/visualType combinations, you may
6166
87e576aea243 class: Image
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
   102
    run into very slow fallback methods. If this leads to problems, you may have to
87e576aea243 class: Image
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
   103
    write a specially tuned (inline-C) version for that case.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   104
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   105
    The pixelFunction enables dynamically computed functional images: instead of
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   106
    providing a byteArray containing pixel data, a function is used which maps
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   107
    x/y coordinates to a pixel value (see examples).
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   108
    For display, the bits array is used internally and filled by the function.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   109
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   110
    Much more work is needed if you plan to do heavy image processing and will
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   111
    (may) be done in the future if there is a demand for it ...
6166
87e576aea243 class: Image
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
   112
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   113
    Dithering can be controlled by the DitherAlgorithm classVariable:
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
   114
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   115
       DitherAlgorithm:
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   116
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   117
       nil                  a simple threshold algorithm
7404
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   118
                            (i.e. for mono, p<0.5 -> black, p>=0.5 -> white)
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   119
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   120
       #pattern             patterned dither
7404
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   121
                            (for p, take dithered color to fill pixel;
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   122
                             uses dithering in color-class)
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   123
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   124
       #error               error diffusion dither (Floyd-Steinberg)
7404
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   125
                            planned - not yet implemented.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   126
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   127
6862
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
   128
    Notice:
7404
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   129
        the set of attributes and the way they are stored originated initially
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   130
        from the need to represent tiff images. These turned out to use a relatively
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   131
        large set of atributes, of which many are unused in other image formats.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   132
        (so it was sufficient).
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   133
        Later, some VisualWorks compatibility protocol was added (mapped palettes, for
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   134
        example), and some stuff could well be redefined in simpler ways.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   135
        We may do that, if we are bored and there is nothing else to improve... ;-)
6862
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
   136
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   137
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   138
    [instance variables:]
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   139
7404
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   140
        width               <Integer>       the width in pixels
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   141
        height              <Integer>       the height in pixels
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   142
        bytes               <ByteArray>     the full image information
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   143
        photometric         <Symbol>        #rgb, #palette, #blackIs0 or #whiteIs0
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   144
        samplesPerPixel     <Integer>       the number of planes
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   145
        bitsPerSample       <Array>         the number of bits per plane
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   146
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   147
        colorMap            <Array>         only if photometric is #palette;
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   148
                                            maps pixel values to r/g/b values.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   149
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   150
        device              <Workstation>   the device on which deviceForm,
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   151
                                            monoDeviceForm and lowResDeviceForm are
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   152
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   153
        deviceForm          <Form>          the device form which gives the best
7621
e6755d298330 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7596
diff changeset
   154
                                            possible approximation of the image on
7404
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   155
                                            device using standard colors.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   156
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   157
        monoDeviceForm      <Form>          the device form which gives a monochrome
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   158
                                            aproximation of the image on device.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   159
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   160
        fullColorDeviceForm <Form>          the device form which gives the best
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   161
                                            possible aproximation of the image on
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   162
                                            device using private colors.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   163
                                            (not yet implemented)
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   164
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   165
        mask                <ImageMask>     an optional mask;
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   166
                                            if non-nil, only pixels for which the
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   167
                                            corresponding mask bit is non-zero
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   168
                                            are drawn.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   169
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   170
        maskedPixelsAre0    <Boolean>       a hint for image processors and drawers
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   171
                                            if true, masked pixels are known to be
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   172
                                            zero in the pixel bytes.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   173
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   174
        fileName            <String>        the name of the file from which the
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   175
                                            image was loaded - nil otherwise.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   176
                                            Useful for image save functions
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   177
                                            and for the UIPainter utility.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   178
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   179
        imageSequence                       the imageSequence, of which the
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   180
                                            instance is a frame or nil,
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   181
                                            if its not part of a sequence.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   182
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   183
        bitsPerPixel                        obsolete - not used in ST/X (kept for a while for subclasses)
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   184
        depth                               - these have been added in instVar-slots
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   185
        maxPixelValue                       - according to the ST-80's image class.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   186
        rowByteSize                         - to allow loading of st-80 images
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   187
                                            - (which are stored as instVarAt:put: expressions)
1288
9af08a658acc added ST-80 dummy instVars - allows ST-80 images stored via #storeOn:
Claus Gittinger <cg@exept.de>
parents: 1279
diff changeset
   188
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   189
    [class variables:]
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   190
7404
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   191
        Lobby               <Registry>      keeps track of known images
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   192
                                            (for resource freeing with garbage collector)
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   193
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   194
        DitherAlgorithm     <Symbol>        defines how to dither
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   195
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   196
        NumberOfDitherColors <Integer>      defines, how many dither colors to use
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   197
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   198
        FileFormats         <Dictionary>    associates filename extensions to
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   199
                                            image reader classes (now set-up in startup-file)
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   200
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   201
        CollectGarbageWhenRunningOutOfColors
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   202
                            <Boolean>       if true, and we run out of available
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   203
                                            device colors during creation of a
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   204
                                            device image, collect garbage for
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   205
                                            possible image reclamation.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   206
                                            If false, proceed immediately.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   207
                                            Default is true.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   208
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   209
        ImageNotFoundQuerySignal
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   210
                            <QuerySignal>   raised, if an image could not be loaded
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   211
                                            from a file. The parameter is the images
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   212
                                            fileName.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   213
                                            A handler may return a replacement
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   214
                                            image or proceed with nil.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   215
                                            If unhandled, a nil is returned from the
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   216
                                            image creation.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   217
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   218
        BadImageFormatQuerySignal
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   219
                            <QuerySignal>   raised, if an image could not be loaded
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   220
                                            from a file due to a file error or
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   221
                                            unsupported format.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   222
                                            A handler may return a replacement
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   223
                                            image or proceed with nil.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   224
                                            If unhandled, a nil is returned from the
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   225
                                            image creation.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   226
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   227
        ImageSaveErrorSignal
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   228
                            <Signal>        parent of errors below.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   229
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   230
        FileCreationErrorSignal
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   231
                            <Signal>        file could not be created when saving an
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   232
                                            image.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   233
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   234
        CannotRepresentImageSignal
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   235
                            <Signal>        the specified ImageReader cannot represent
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   236
                                            the given image.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   237
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   238
        InformationLostQuerySignal
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   239
                            <Signal>        the specified ImageReader can represent
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   240
                                            the given image, but some information
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   241
                                            (typically color resolution) is lost.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   242
                                            If unhandled, the save proceeds as usual.
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
   243
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
   244
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
   245
    caveat:
7404
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   246
        the information in
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   247
            photometric, bitsPerPixel, bitsPerSample, samplesPerPixel, depth , colorMap and maxPixelValue
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   248
        is partially redundant and its handling stupid (not to say: braindamaged ;-).
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   249
        The only excuse is that it grew over time, had to incorporate various alien/older schemes for
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   250
        compatibility reasons (mostly coming from tiff format, which was the very first supported format).
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   251
        All of the above belongs into the single colorMap which must migrate from
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   252
        a stupid seqColl to a color-aware real colorMap.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   253
        (we are in the process of doing so...)
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
   254
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   255
    todo:
7404
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   256
        support alpha masks
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   257
        cleanup the dithering & conversion code
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   258
        cleanup the color/photometric mess
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   259
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   260
    [See also:]
7404
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   261
        Form Icon ImageReader
611
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   262
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   263
    [author:]
7404
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   264
        Claus Gittinger
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   265
"
649
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   266
!
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   267
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   268
examples
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   269
"
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   270
    reading from a file (many formats are supported):
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   271
    (notice that the bitmaps directory is searched for along
2645
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   272
     the system path - therefore, you may add your own bitmap
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   273
     directory to the beginning of the path and thus override
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   274
     any default bitmaps, or make certain that your application
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   275
     finds its bitmaps - even if they are in a separate directory)
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   276
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   277
                                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   278
        (Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif') inspect
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   279
                                                                                        [exEnd]
7523
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
   280
    Boy, was I young, when writing ST/X... ;-)                                                                                                 
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
   281
                                                                                        [exBegin]
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
   282
        (Image fromFile:'../../goodies/bitmaps/gifImages/claus.gif') inspect
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
   283
        ((Image fromFile:'../../goodies/bitmaps/gifImages/claus.gif') rotated:90) inspect
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
   284
        ((Image fromFile:'../../goodies/bitmaps/gifImages/claus.gif') rotated:45) inspect
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
   285
        ((Image fromFile:'../../goodies/bitmaps/gifImages/claus.gif') rotated:25) inspect
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
   286
                                                                                        [exEnd]
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
   287
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
   288
                                                                                        
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   289
    better use package relative file names:
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   290
                                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   291
        (Image fromFile:'bitmaps/gifImages/garfield.gif' inPackage:'stx:goodies') inspect
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   292
                                                                                        [exEnd]
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   293
    various file formats are supported:
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   294
                                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   295
        (Image fromFile:'bitmaps/xpmBitmaps/misc_icons/SmalltalkX_clr.xpm' inPackage:'stx:goodies') inspect
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   296
                                                                                        [exEnd]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   297
                                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   298
        (Image fromFile:'bitmaps/winBitmaps/okSmily_up.bmp' inPackage:'stx:goodies') inspect
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   299
                                                                                        [exEnd]
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   300
7222
matilk
parents: 7210
diff changeset
   301
    drawing
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   302
                                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   303
        |imageClass image|
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   304
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   305
        imageClass := Image implementorForDepth:24.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   306
        image      := imageClass width: 100 height: 50.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   307
        image bits:(ByteArray new:(image bytesPerRow*50)).
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   308
        image fillRectangle:(0@0 extent:100@50) withColor:Color yellow.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   309
        image drawRectangle:(10@10 extent:20@20) withColor:Color red.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   310
        image fillRectangle:(40@20 extent:20@20) withColor:Color green.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   311
                                                                                        [exEnd]
7222
matilk
parents: 7210
diff changeset
   312
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   313
    The following examples demonstrate various depth and colorMap variations ...
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   314
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   315
    inline image:
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   316
      default: depth=1 & #blackIs0
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   317
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   318
        (Image
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   319
            width:8 height:8
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   320
            fromArray:#( 2r11111111
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   321
                         2r10000001
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   322
                         2r10000001
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   323
                         2r10000001
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   324
                         2r10000001
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   325
                         2r10000001
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   326
                         2r10000001
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   327
                         2r11111111 )
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   328
        ) edit
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   329
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   330
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   331
      with #whiteIs0 photometric
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   332
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   333
        ((Image width:8 height:8
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   334
               fromArray:#( 2r11111111
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   335
                            2r10000001
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   336
                            2r10000001
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   337
                            2r10000001
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   338
                            2r10000001
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   339
                            2r10000001
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   340
                            2r10000001
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   341
                            2r11111111 ))
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   342
            photometric:#whiteIs0
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   343
        ) edit
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   344
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   345
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   346
      with a colorMap
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   347
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   348
        ((Image width:8 height:8
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   349
               fromArray:#( 2r11111111
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   350
                            2r10000001
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   351
                            2r10000001
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   352
                            2r10000001
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   353
                            2r10000001
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   354
                            2r10000001
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   355
                            2r10000001
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   356
                            2r11111111 ))
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   357
            colorMap:(Array with:(Color red)
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   358
                            with:(Color yellow))
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   359
        ) edit
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   360
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   361
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   362
      a depth4 greyScale image:
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   363
      (default photometric is #blackIs0)
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   364
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   365
        (Depth4Image
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   366
             width:8
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   367
             height:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   368
             fromArray:#[
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   369
                            16r00 16r11 16r22 16r33
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   370
                            16r44 16r55 16r66 16r77
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   371
                            16r88 16r99 16raa 16rbb
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   372
                            16rcc 16rdd 16ree 16rff
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   373
                        ]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   374
        ) edit
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   375
                                                                        [exEnd]
2645
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   376
      the same, magnified:
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   377
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   378
        ((Depth4Image
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   379
             width:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   380
             height:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   381
             fromArray:#[
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   382
                            16r01 16r23
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   383
                            16r45 16r67
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   384
                            16r89 16rab
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   385
                            16rcd 16ref
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   386
                        ])
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   387
            magnifiedBy:30
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   388
        ) edit
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   389
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   390
      the following has the same effect:
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   391
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   392
        ((Image
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   393
             width:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   394
             height:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   395
             depth:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   396
             fromArray:#[
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   397
                            16r01 16r23
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   398
                            16r45 16r67
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   399
                            16r89 16rab
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   400
                            16rcd 16ref
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   401
                        ])
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   402
            magnifiedBy:30
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   403
        ) edit
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   404
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   405
      with reverse grey-interpretation:
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   406
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   407
        ((Depth4Image
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   408
             width:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   409
             height:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   410
             fromArray:#[
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   411
                            16r01 16r23
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   412
                            16r45 16r67
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   413
                            16r89 16rab
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   414
                            16rcd 16ref
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   415
                        ])
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   416
            photometric:#whiteIs0;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   417
            magnifiedBy:30
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   418
        ) edit
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   419
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   420
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   421
      with 1-bit-per-pixel rgb interpretation:
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   422
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   423
        ((Depth4Image
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   424
             width:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   425
             height:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   426
             fromArray:#[
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   427
                            16r01 16r23
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   428
                            16r45 16r67
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   429
                            16r89 16rab
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   430
                            16rcd 16ref
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   431
                        ])
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   432
            photometric:#rgb;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   433
            samplesPerPixel:3;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   434
            bitsPerSample:#(1 1 1);
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   435
            magnifiedBy:30
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   436
        ) edit
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   437
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   438
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   439
      with 1/2/1 rgb interpretation:
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   440
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   441
        ((Depth4Image
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   442
             width:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   443
             height:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   444
             fromArray:#[
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   445
                            16r01 16r23
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   446
                            16r45 16r67
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   447
                            16r89 16rab
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   448
                            16rcd 16ref
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   449
                        ])
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   450
            photometric:#rgb;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   451
            samplesPerPixel:3;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   452
            bitsPerSample:#(1 2 1);
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   453
            magnifiedBy:30
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   454
        ) edit
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   455
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   456
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   457
      a 2/2/0 rgb image (i.e. no blue):
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   458
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   459
         |i|
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   460
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   461
         i := Depth4Image
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   462
                    width:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   463
                    height:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   464
                    fromArray:#[ 16r01 16r23
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   465
                                 16r45 16r67
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   466
                                 16r89 16rab
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   467
                                 16rcd 16ref ].
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   468
         i photometric:#rgb.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   469
         i samplesPerPixel:3.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   470
         i bitsPerSample:#(2 2 0).
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   471
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   472
         i := i magnifiedBy:30.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   473
         i edit.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   474
                                                                        [exEnd]
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   475
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   476
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   477
      a 0/0/4 rgb image (i.e. no red or green):
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   478
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   479
         |i|
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   480
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   481
         i := Depth4Image
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   482
                    width:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   483
                    height:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   484
                    fromArray:#[ 16r01 16r23
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   485
                                 16r45 16r67
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   486
                                 16r89 16rab
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   487
                                 16rcd 16ref ].
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   488
         i photometric:#rgb.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   489
         i samplesPerPixel:3.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   490
         i bitsPerSample:#(0 0 4).
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   491
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   492
         i := i magnifiedBy:30.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   493
         i edit.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   494
                                                                        [exEnd]
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   495
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   496
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   497
      a 2plane greyscale image:
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   498
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   499
        ((Depth2Image
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   500
             width:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   501
             height:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   502
             fromArray:#[
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   503
                            4r0123
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   504
                            4r1230
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   505
                            4r2301
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   506
                            4r3012
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   507
                        ])
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   508
            magnifiedBy:30
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   509
        ) edit
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   510
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   511
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   512
      with colors:
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   513
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   514
        ((Depth2Image
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   515
             width:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   516
             height:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   517
             fromArray:#[
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   518
                            4r0123
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   519
                            4r1230
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   520
                            4r2301
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   521
                            4r3012
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   522
                        ])
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   523
            colorMap:(Array with:(Color black)
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   524
                            with:(Color red)
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   525
                            with:(Color green)
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   526
                            with:(Color blue));
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   527
            magnifiedBy:30
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   528
        ) edit
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   529
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   530
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   531
      depth8 image with 3/3/2 rgb interpretation:
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   532
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   533
        ((Depth8Image
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   534
             width:16
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   535
             height:16
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   536
             fromArray:(ByteArray withAll:(0 to:16rFF)))
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   537
            photometric:#rgb;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   538
            samplesPerPixel:3;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   539
            bitsPerSample:#(3 3 2);
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   540
            magnifiedBy:10
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   541
        ) edit
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   542
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   543
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   544
      depth8 image with 2/2/2 rgb interpretation:
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   545
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   546
        ((Depth8Image
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   547
             width:8
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   548
             height:8
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   549
             fromArray:(ByteArray withAll:(0 to:16r3F)))
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   550
            photometric:#rgb;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   551
            samplesPerPixel:3;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   552
            bitsPerSample:#(2 2 2);
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   553
            magnifiedBy:10
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   554
        ) edit
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   555
                                                                        [exEnd]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   556
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   557
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   558
        ((Depth8Image
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   559
             width:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   560
             height:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   561
             fromArray:#[
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   562
                    16r30 16r0C  16r03 16r3F
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   563
                    16r20 16r08  16r02 16r2A
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   564
                    16r10 16r04  16r01 16r15
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   565
                    16r00 16r00  16r00 16r00
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   566
                        ])
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   567
            photometric:#rgb;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   568
            samplesPerPixel:3;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   569
            bitsPerSample:#(2 2 2);
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   570
            magnifiedBy:30
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   571
        ) edit
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   572
                                                                        [exEnd]
5126
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   573
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   574
      trueColor image: remember: bytes are MSB
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   575
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   576
        ((Depth16Image
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   577
             width:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   578
             height:5
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   579
             fromArray:#[
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   580
                    2r01111100 2r00000000  2r00000011 2r11100000  2r00000000 2r00011111  2r01111111 2r11111111
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   581
                    2r00111100 2r00000000  2r00000001 2r11100000  2r00000000 2r00001111  2r00111101 2r11101111
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   582
                    2r00011100 2r00000000  2r00000000 2r11100000  2r00000000 2r00000111  2r00011100 2r11100111
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   583
                    2r00001100 2r00000000  2r00000000 2r01100000  2r00000000 2r00000001  2r00001100 2r01100011
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   584
                    2r00000100 2r00000000  2r00000000 2r00100000  2r00000000 2r00000001  2r00000100 2r00100001
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   585
                        ])
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   586
            photometric:#rgb;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   587
            samplesPerPixel:3;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   588
            bitsPerSample:#(5 5 5);
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   589
            magnifiedBy:30
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   590
        ) edit
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   591
                                                                        [exEnd]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   592
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   593
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   594
        ((Depth24Image
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   595
             width:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   596
             height:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   597
             fromArray:#[
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   598
                    16rFF 16r00 16r00  16rFF 16r00 16r00  16rFF 16r00 16r00  16rFF 16r00 16r00
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   599
                    16r00 16rFF 16r00  16r00 16rFF 16r00  16r00 16rFF 16r00  16r00 16rFF 16r00
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   600
                    16r00 16r00 16rFF  16r00 16r00 16rFF  16r00 16r00 16rFF  16r00 16r00 16rFF
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   601
                    16rFF 16rFF 16rFF  16rFF 16rFF 16rFF  16rFF 16rFF 16rFF  16rFF 16rFF 16rFF
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   602
                        ])
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   603
            photometric:#rgb;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   604
            samplesPerPixel:3;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   605
            bitsPerSample:#(8 8 8);
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   606
            magnifiedBy:30
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   607
        ) edit
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   608
                                                                        [exEnd]
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   609
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   610
      32bit trueColor image:
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   611
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   612
        ((Depth32Image
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   613
             width:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   614
             height:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   615
             fromArray:#[
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   616
                    16rFF 16r00 16r00 16r00  16rFF 16r00 16r00 16r00  16rFF 16r00 16r00 16r00  16rFF 16r00 16r00 16r00
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   617
                    16r00 16rFF 16r00 16r00  16r00 16rFF 16r00 16r00  16r00 16rFF 16r00 16r00  16r00 16rFF 16r00 16r00
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   618
                    16r00 16r00 16rFF 16r00  16r00 16r00 16rFF 16r00  16r00 16r00 16rFF 16r00  16r00 16r00 16rFF 16r00
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   619
                    16rFF 16rFF 16rFF 16r00  16rFF 16rFF 16rFF 16r00  16rFF 16rFF 16rFF 16r00  16rFF 16rFF 16rFF 16r00
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   620
                        ])
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   621
            photometric:#rgb;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   622
            samplesPerPixel:4;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   623
            bitsPerSample:#(8 8 8 8);
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   624
            magnifiedBy:30
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   625
        ) edit
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   626
                                                                        [exEnd]
2760
94d2d524081b example added (24-bit image)
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   627
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   628
    storing - only a subset of formats (TIFF, XBM, XPM) currently support storing:
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   629
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   630
        |img|
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   631
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   632
        img := Image fromFile:'bitmaps/winBitmaps/okSmily_up.bmp' inPackage:'stx:goodies'.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   633
        img saveOn:'myImage.tiff'.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   634
        (Image fromFile:'myImage.tiff') inspect.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   635
        img saveOn:'myImage.gif'.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   636
        (Image fromFile:'myImage.gif') inspect.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   637
                                                                        [exEnd]
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   638
649
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   639
    magnifying (any factor):
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   640
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   641
        ((Image fromFile:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies')
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   642
            magnifiedTo:(48@48))
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   643
                inspect
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   644
                                                                        [exEnd]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   645
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   646
        ((Image fromFile:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies')
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   647
            magnifiedBy:0.7)
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   648
                inspect
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   649
                                                                        [exEnd]
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   650
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   651
    rotating (any angle in degrees clockwise):
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   652
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   653
        ((Image fromFile:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies')
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   654
            rotated:90)
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   655
                inspect
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   656
                                                                        [exEnd]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   657
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   658
        (((Image fromFile:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies')
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   659
            magnifiedBy:0.3@0.7) rotated:270)
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   660
                inspect
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   661
                                                                        [exEnd]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   662
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   663
        (((Image fromFile:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies')
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   664
            ) rotated:30)
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   665
                inspect
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   666
                                                                        [exEnd]
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   667
    negative:
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   668
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   669
        ((Image fromFile:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies')
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   670
            negative)
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   671
                inspect
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   672
                                                                        [exEnd]
7123
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   673
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   674
      depth32 image with 8+8+8+8 argb interpretation:
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   675
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   676
        ((Depth32Image
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   677
             width:4 height:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   678
             fromArray:#[
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   679
                255 255 0 0       255 255 0 0       255 255 0 0       255 255 0 0
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   680
                255 0 255 0       255 0 255 0       255 0 255 0       255 0 255 0
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   681
                255 0 0 255       255 0 0 255       255 0 0 255       255 0 0 255
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   682
                255 255 255 255   255 255 255 255   255 255 255 255   255 255 255 255 ])
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   683
            photometric:#argb;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   684
            samplesPerPixel:4;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   685
            bitsPerSample:#(8 8 8 8);
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   686
            magnifiedBy:10
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   687
        ) edit
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   688
                                                                        [exEnd]
7123
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   689
7126
a81b992fd069 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7123
diff changeset
   690
      depth32 image with 8+8+8+8 rgba interpretation:
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   691
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   692
        ((Depth32Image
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   693
             width:4 height:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   694
             fromArray:#[
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   695
                255 0 0 255       255 0 0 255       255 0 0 255       255 0 0 255
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   696
                0 255 0 255       0 255 0 255       0 255 0 255       0 255 0 255
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   697
                0 0 255 255       0 0 255 255       0 0 255 255       0 0 255 255
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   698
                255 255 255 255   255 255 255 255   255 255 255 255   255 255 255 255 ])
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   699
            photometric:#rgba;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   700
            samplesPerPixel:4;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   701
            bitsPerSample:#(8 8 8 8);
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   702
            magnifiedBy:10
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   703
        ) edit
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   704
                                                                        [exEnd]
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   705
"
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   706
!
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   707
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   708
examples_functionalImages
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   709
"
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   710
    Functional images (please read 'Functional Images' by Conal Elliot, Microsoft Research).
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
   711
    These have no underyling pixelstorage, but instead compute the pixel-value via a block.
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   712
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   713
    Plain x/y mapping:
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   714
                                                                        [exBegin]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   715
        |i|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   716
        i := Depth1Image extent:256@256.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   717
        i pixelFunction:[:x :y | ((x // 16) bitXor:(y // 16)) odd ifTrue:1 ifFalse:[0]].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   718
        i inspect.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   719
                                                                        [exEnd]
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   720
    Transformed x/y mapping:
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   721
                                                                        [exBegin]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   722
        |i f|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   723
        f := [:x :y | (x between:0.4 and:0.6) asInteger].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   724
        i := Depth1Image extent:256@256.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   725
        i pixelFunction:f inX:(0.0 to:1.0) y:(0.0 to:1.0).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   726
        i inspect.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   727
                                                                        [exEnd]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   728
                                                                        [exBegin]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   729
        |i f|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   730
        f := [:x :y | ((x between:0.4 and:0.6) or:[(y between:0.4 and:0.6)]) asInteger].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   731
        i := Depth1Image extent:256@256.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   732
        i pixelFunction:f inX:(0.0 to:1.0) y:(0.0 to:1.0).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   733
        i inspect.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   734
                                                                        [exEnd]
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   735
    Image based on polar coordinate:
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   736
                                                                        [exBegin]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   737
        |i f|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   738
        f := [:x :y | ((x@y) r * 10) asInteger bitAnd:1].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   739
        i := Depth1Image extent:256@256.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   740
        i pixelFunction:f inX:(-1.0 to:1.0) y:(-1.0 to:1.0).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   741
        i inspect.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   742
                                                                        [exEnd]
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   743
    Grayscale image based on polar coordinate:
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   744
                                                                        [exBegin]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   745
        |i|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   746
        i := Depth8Image extent:256@256.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   747
        i photometric:#blackIs0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   748
        i pixelFunction:[:x :y | ((x@y) r * 255) truncated min:255] inX:(-1 to:1) y:(-1 to:1).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   749
        i inspect.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   750
                                                                        [exEnd]
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   751
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   752
    Taking another image as ''input''
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   753
                                                                        [exBegin]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   754
        |garfield f i h|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   755
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   756
        garfield := Image fromFile:'bitmaps/gifImages/garfield.gif' inPackage:'stx:goodies'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   757
        h := garfield height.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   758
        f := [:x :y | (garfield colorAtX:x y:h-y) rgbValue].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   759
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   760
        i := Depth24Image extent:garfield extent.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   761
        i pixelFunction:f.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   762
        i inspect.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   763
                                                                        [exEnd]
649
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   764
"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   765
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
   766
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   767
!Image class methodsFor:'initialization'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   768
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   769
addReader:aReaderClass suffix:aSuffix
5216
f7ec910cfce1 Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 5200
diff changeset
   770
    <resource: #obsolete>
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   771
    "register an additional image reader.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   772
     This is provided for subclasses, to regster themself when
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   773
     loaded (or from the startup scripts)"
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   774
1800
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   775
    self obsoleteMethodWarning.
1780
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   776
    self addReader:aReaderClass suffix:aSuffix mimeType:nil
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   777
!
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   778
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   779
addReader:aReaderClass suffix:aSuffix mimeType:mimeType
5216
f7ec910cfce1 Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 5200
diff changeset
   780
    <resource: #obsolete>
1780
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   781
    "register an additional image reader.
1800
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   782
     This interface is kept for backward compatibility.
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   783
     The knowledge has been concentrated in MIMETypes"
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   784
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   785
    self obsoleteMethodWarning.
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   786
    MIMETypes
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   787
        defineImageType:mimeType suffix:aSuffix reader:aReaderClass
1780
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   788
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   789
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   790
     Image addReader:GIFReader suffix:'gif'
1780
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   791
     Image addReader:GIFReader suffix:'gif' mimeType:'image/gif'
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   792
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   793
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   794
    "Modified: 30.6.1997 / 21:59:59 / cg"
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   795
!
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   796
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   797
fileFormats
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   798
    "return the collection of supported file formats.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   799
     The returned dictionary maps file-extensions to image reader classes."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   800
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   801
    ^ MIMETypes fileSuffixToImageReaderMapping
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   802
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   803
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   804
     Image fileFormats
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   805
    "
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   806
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   807
    "Modified: 30.6.1997 / 22:05:58 / cg"
100
1b0b86c77397 co !!:*
claus
parents: 89
diff changeset
   808
!
1b0b86c77397 co !!:*
claus
parents: 89
diff changeset
   809
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   810
flushDeviceImages
869
464ffa8c0c67 comment
Claus Gittinger <cg@exept.de>
parents: 861
diff changeset
   811
    "simply release all deviceForms"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   812
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   813
    Lobby do:[:anImage |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   814
        anImage release
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   815
    ]
869
464ffa8c0c67 comment
Claus Gittinger <cg@exept.de>
parents: 861
diff changeset
   816
464ffa8c0c67 comment
Claus Gittinger <cg@exept.de>
parents: 861
diff changeset
   817
    "Modified: 15.6.1996 / 15:45:02 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   818
!
48194c26a46c Initial revision
claus
parents:
diff changeset
   819
48194c26a46c Initial revision
claus
parents:
diff changeset
   820
initialize
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
   821
    "initialize class constants"
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
   822
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   823
    "setup tracker of known pictures"
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   824
    Lobby isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   825
        Lobby := Registry new.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   826
        ObjectMemory addDependent:self.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   827
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   828
        "/ define the algorithm to use for dithering -
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   829
        "/ supported values are:
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   830
        "/      #threshold
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   831
        "/      #ordered
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   832
        "/      #floydSteinberg
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   833
        "/      #burkes
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   834
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   835
        DitherAlgorithm := #floydSteinberg.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   836
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   837
        (Display notNil and:[Display hasGrayscales]) ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   838
            NumberOfDitherColors := 64
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   839
        ] ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   840
            "as far as I remember, this is about the number of grey values, the eye can distinguish"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   841
            NumberOfDitherColors := 100
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   842
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   843
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   844
        "define reader classes"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   845
        self initializeFileFormatTable.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   846
        self initializeMIMETable.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   847
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   848
        CollectGarbageWhenRunningOutOfColors := false.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   849
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   850
        ImageErrorSignal := Error newSignalMayProceed:true.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   851
        ImageErrorSignal nameClass:self message:#imageErrorSignal.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   852
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   853
        ImageSaveErrorSignal := ImageErrorSignal newSignalMayProceed:true.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   854
        ImageSaveErrorSignal nameClass:self message:#imageSaveErrorSignal.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   855
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   856
        FileCreationErrorSignal := ImageSaveErrorSignal newSignalMayProceed:true.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   857
        FileCreationErrorSignal nameClass:self message:#fileCreationErrorSignal.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   858
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   859
        CannotRepresentImageSignal := ImageSaveErrorSignal newSignalMayProceed:true.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   860
        CannotRepresentImageSignal nameClass:self message:#cannotRepresentImageSignal.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   861
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   862
        ImageLoadErrorSignal := QuerySignal new.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   863
        ImageLoadErrorSignal nameClass:self message:#imageLoadErrorSignal.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   864
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   865
        ImageNotFoundQuerySignal := QuerySignal new.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   866
        ImageNotFoundQuerySignal nameClass:self message:#imageNotFoundQuerySignal.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   867
        ImageNotFoundQuerySignal parent:ImageLoadErrorSignal.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   868
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   869
        InformationLostQuerySignal := QuerySignal new.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   870
        InformationLostQuerySignal nameClass:self message:#informationLostQuerySignal.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   871
        InformationLostQuerySignal parent:ImageLoadErrorSignal.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   872
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   873
        BadImageFormatQuerySignal := QuerySignal new.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   874
        BadImageFormatQuerySignal nameClass:self message:#badImageFormatQuerySignal.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   875
        BadImageFormatQuerySignal parent:ImageLoadErrorSignal.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   876
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   877
        UnrepresentableColorSignal := ImageErrorSignal newSignalMayProceed:true.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   878
        UnrepresentableColorSignal nameClass:self message:#unrepresentableColorSignal.
7170
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   879
    ].
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   880
    UninterpretedBytes isBigEndian ifTrue:[
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   881
        ARGB_A_OFFSET_MACHINE := 1.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   882
        ARGB_R_OFFSET_MACHINE := 2.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   883
        ARGB_G_OFFSET_MACHINE := 3.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   884
        ARGB_B_OFFSET_MACHINE := 4.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   885
    ] ifFalse:[ 
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   886
        ARGB_A_OFFSET_MACHINE := 4.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   887
        ARGB_R_OFFSET_MACHINE := 3.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   888
        ARGB_G_OFFSET_MACHINE := 2.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   889
        ARGB_B_OFFSET_MACHINE := 1.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   890
    ].
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   891
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   892
    "Modified: / 18-05-1999 / 15:50:03 / cg"
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   893
    "Modified: / 28-02-2016 / 14:36:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   894
!
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   895
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   896
initializeFileFormatTable
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   897
    "initialize a default table to map from file extension to reader class.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   898
     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
   899
     see the 'smalltalk.rc'/'display.rc' startup files for a real (full) map."
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   900
1814
5d413419cf51 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1802
diff changeset
   901
    MIMETypes notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   902
        MIMETypes imageReaderForSuffix:'xbm'  put:XBMReader.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   903
        MIMETypes imageReaderForSuffix:'tiff' put:TIFFReader.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   904
        MIMETypes imageReaderForSuffix:'gif'  put:GIFReader.
1814
5d413419cf51 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1802
diff changeset
   905
    ].
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   906
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   907
    "
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   908
     Image initializeFileFormatTable
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   909
    "
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   910
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   911
    "Modified: 30.6.1997 / 22:07:28 / cg"
1785
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   912
!
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   913
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   914
initializeMIMETable
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   915
    "initialize a default table to map from mime type to reader class.
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   916
     The mapping here is a default needed for proper operation of ST/X;
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   917
     see the 'smalltalk.rc'/'display.rc' startup files for a real (full) map."
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   918
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   919
    MIMETypes notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   920
        MIMETypes mimeTypeForSuffix:'gif'       put:'image/gif'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   921
        MIMETypes mimeTypeForSuffix:'tiff'      put:'image/tiff'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   922
        MIMETypes mimeTypeForSuffix:'tif'       put:'image/tiff'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   923
        MIMETypes mimeTypeForSuffix:'xbm'       put:'image/x-xbitmap'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   924
        MIMETypes mimeTypeForSuffix:'xpm'       put:'image/x-xpixmap'.
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   925
    ].
1785
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   926
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   927
    "
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   928
     Image initializeMIMETable
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   929
    "
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   930
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   931
    "Created: 27.6.1997 / 16:43:48 / cg"
1815
50212910fc13 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   932
    "Modified: 21.7.1997 / 17:33:59 / cg"
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   933
!
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   934
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
   935
update:something with:aParameter from:changedObject
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   936
    "flush all device specific stuff when restarted from a snapshot"
48194c26a46c Initial revision
claus
parents:
diff changeset
   937
48194c26a46c Initial revision
claus
parents:
diff changeset
   938
    (something == #restarted) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   939
        self flushDeviceImages
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   940
    ]
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
   941
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
   942
    "Created: 21.6.1996 / 19:47:43 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   943
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
   944
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   945
!Image class methodsFor:'instance creation'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   946
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   947
extent:ext
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   948
    "create a new image, given extent.
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   949
     Assume a depth of 1, unless an explicit imageClass is the receiver."
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   950
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   951
    ^ self width:(ext x) height:(ext y)
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   952
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   953
    "Created: / 30.9.1998 / 22:31:26 / cg"
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   954
    "Modified: / 30.9.1998 / 22:32:48 / cg"
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   955
!
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   956
3023
cb063801decd more Squeak compatibility
ps
parents: 2980
diff changeset
   957
extent:ext depth:d
cb063801decd more Squeak compatibility
ps
parents: 2980
diff changeset
   958
    "ST-80 compatibility"
cb063801decd more Squeak compatibility
ps
parents: 2980
diff changeset
   959
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   960
    ^ self width:ext x height:ext y depth:d
3023
cb063801decd more Squeak compatibility
ps
parents: 2980
diff changeset
   961
!
cb063801decd more Squeak compatibility
ps
parents: 2980
diff changeset
   962
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   963
extent:ext depth:d antiAliasedPalette:aBasicColorArray bgColor:bgColor
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   964
    ^ self extent:ext depth:d antiAliasedPalette:aBasicColorArray bgColor:bgColor mixedArray:#(1.0 0.8 0.6 0.4 0.2)
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   965
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   966
    "
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   967
        |colorMap aaImgArray|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   968
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   969
        colorMap := Array with:Color white with:Color blue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   970
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   971
        aaImgArray := Depth8Image extent:300@400 depth:8 antiAliasedPalette:colorMap bgColor:Color white.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   972
        aaImgArray last
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   973
            fillAntiAliasedArc:200@200
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   974
            radius:80
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   975
            from:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   976
            angle:360
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   977
            withColor:Color blue
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   978
            antiAliasedPalette:aaImgArray first
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   979
            startWith:aaImgArray second.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   980
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   981
        aaImgArray last inspect.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   982
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   983
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   984
        |colorMap aaImgArray|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   985
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   986
        colorMap := Array with:Color white with:Color black with:Color red with:Color blue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   987
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   988
        aaImgArray := Depth8Image extent:300@400 depth:8 antiAliasedPalette:colorMap bgColor:Color white.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   989
        aaImgArray last fillAntiAliasedArc:205@195 radius:80 from:0 angle:90 withColor:Color red
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   990
            colorDictionary:aaImgArray first
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   991
            blendStart:aaImgArray second.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   992
        aaImgArray last fillAntiAliasedArc:200@200 radius:80 from:90 angle:270 withColor:Color blue
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   993
            colorDictionary:aaImgArray first
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   994
            blendStart:aaImgArray second.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   995
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   996
        aaImgArray last inspect.
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   997
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   998
    "
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   999
!
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1000
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1001
extent:ext depth:d antiAliasedPalette:aBasicColorArray bgColor:bgColor mixedArray:mixedArray
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1002
    |colorMap colorIndex colorDictionary tmpDic newImage|
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1003
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1004
    colorMap := OrderedCollection new.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1005
    colorIndex := 0.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1006
    colorDictionary := Dictionary new.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1007
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1008
    aBasicColorArray do:[:aColor |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1009
        colorMap add:aColor.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1010
        colorIndex := colorIndex + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1011
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1012
        tmpDic := Dictionary new.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1013
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1014
        mixedArray do:[:aFloat |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1015
            tmpDic at:aFloat put:colorIndex.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1016
            colorMap add:(aColor mixed:aFloat with:bgColor).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1017
            colorIndex := colorIndex + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1018
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1019
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1020
        colorDictionary at:aColor put:tmpDic.
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1021
    ].
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1022
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1023
    newImage := (self implementorForDepth:d) new.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1024
    newImage width:ext x height:ext y depth:d palette:colorMap.
5643
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1025
    newImage createPixelStore.
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1026
"/    emptyBits := ByteArray new:(newImage bytesPerRow * ext y).
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1027
"/    newImage bits:emptyBits.
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1028
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  1029
    ^ Array with:colorDictionary with:mixedArray first with:newImage
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  1030
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  1031
    "
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1032
        |colorMap aaImgArray|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1033
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1034
        colorMap := Array with:Color white with:Color black with:Color red with:Color blue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1035
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1036
        aaImgArray := Depth8Image extent:300@400 depth:8 antiAliasedPalette:colorMap bgColor:Color white.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1037
        aaImgArray last fillAntiAliasedArc:205@195 radius:80 from:0 angle:90 withColor:Color red
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1038
            colorDictionary:aaImgArray first
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1039
            blendStart:aaImgArray second.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1040
        aaImgArray last fillAntiAliasedArc:200@200 radius:80 from:90 angle:270 withColor:Color blue
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1041
            colorDictionary:aaImgArray first
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1042
            blendStart:aaImgArray second.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1043
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1044
        aaImgArray last inspect.
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  1045
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  1046
 ###################
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  1047
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1048
        |colorMap aaImgArray|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1049
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1050
        colorMap := Array with:Color white with:Color blue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1051
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1052
        aaImgArray := Depth8Image extent:300@400 depth:8 antiAliasedPalette:colorMap bgColor:Color white.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1053
        aaImgArray last
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1054
            fillAntiAliasedArc:200@200
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1055
            radius:80
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1056
            from:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1057
            angle:360
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1058
            withColor:Color blue
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1059
            colorDictionary:aaImgArray first
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1060
            blendStart:aaImgArray second.
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1061
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1062
        aaImgArray last inspect.
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1063
    "
5643
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1064
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1065
    "Modified: / 02-11-2010 / 20:57:41 / cg"
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1066
    "Modified: / 31-01-2017 / 14:30:22 / stefan"
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1067
    "Modified (comment): / 31-01-2017 / 15:47:39 / stefan"
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1068
!
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1069
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1070
extent:ext depth:d bits:bits
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1071
    "ST-80 compatibility; assume 32-bit padding"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1072
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1073
    ^ self extent:ext depth:d bits:bits pad:32
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
  1074
!
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
  1075
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1076
extent:ext depth:d bits:bits pad:padding
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1077
    "ST-80 compatibility"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1078
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1079
    ^ self width:ext x height:ext y depth:d fromArray:bits pad:padding
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
  1080
!
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
  1081
1276
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1082
extent:ext depth:d bitsPerPixel:bpp palette:aColormap usingBits:bits
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1083
    "ST-80 compatibility"
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1084
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1085
    |img|
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1086
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1087
    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
  1088
    img colorMap:aColormap.
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1089
    ^ img
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1090
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1091
    "Created: 25.1.1997 / 03:50:22 / cg"
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1092
    "Modified: 25.1.1997 / 12:27:35 / cg"
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1093
!
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1094
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1095
extent:ext depth:d palette:aColormap
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1096
    "create & return a blank image of the given size.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1097
     ST-80 compatibility"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1098
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1099
    |newImage|
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1100
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1101
    newImage := (self implementorForDepth:d) new.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1102
    newImage width:ext x height:ext y depth:d palette:aColormap.
5643
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1103
    newImage createPixelStore.
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1104
"/    emptyBits := ByteArray new:(newImage bytesPerRow * ext y).
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1105
"/    newImage bits:emptyBits.
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1106
    ^ newImage
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1107
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1108
    "
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1109
     Image extent:16@16 depth:8 palette:nil
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1110
     Image extent:16@16 depth:4 palette:nil
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1111
     Image extent:16@16 depth:2 palette:nil
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1112
    "
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1113
5643
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1114
    "Created: / 06-03-1997 / 15:24:01 / cg"
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1115
    "Modified: / 02-11-2010 / 20:56:53 / cg"
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1116
    "Modified (format): / 31-01-2017 / 14:51:03 / stefan"
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1117
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1118
1070
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1119
extent:ext depth:d palette:aColormap bits:bits
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1120
    "ST-80 compatibility"
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1121
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1122
    ^ self extent:ext depth:d palette:aColormap bits:bits pad:16
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1123
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1124
    "Modified: 7.10.1996 / 11:32:16 / cg"
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1125
!
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1126
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1127
extent:ext depth:d palette:aColormap bits:bits pad:padding
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1128
    "ST-80 compatibility"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1129
1070
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1130
    |img|
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1131
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1132
    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
  1133
    img colorMap:aColormap.
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1134
    ^ img
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1135
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1136
    "Modified: 7.10.1996 / 11:32:00 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1137
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1138
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1139
extent:ext fromArray:bits offset:offset
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1140
    "ST-80 compatibility"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1141
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1142
    ^ self width:ext x height:ext y fromArray:bits
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1143
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1144
7637
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  1145
fromDeviceForm:aForm maskForm:aMaskFormOrNil
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  1146
    "create & return an image form aForm that is already on a device"
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  1147
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  1148
    |img|
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  1149
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  1150
    img := self newForDepth:aForm depth.
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  1151
    img fromDeviceForm:aForm maskForm:aMaskFormOrNil.
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  1152
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  1153
    ^ img 
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  1154
!
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  1155
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1156
fromForm:aForm
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1157
    "create & return an Image given a aForm"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1158
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1159
    ^ self fromSubForm:(0@0 extent:aForm extent) in:aForm
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1160
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1161
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1162
     |f|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1163
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1164
     f := Form width:16 height:16.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1165
     f clear.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1166
     f displayLineFromX:0 y:0 toX:15 y:15.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1167
     f inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1168
     (Image fromForm:f) inspect
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1169
    "
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1170
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1171
    "
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1172
     |f|
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1173
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1174
     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
  1175
     f clear.
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1176
     f paint:(Color red).
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1177
     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
  1178
     f paint:(Color green).
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1179
     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
  1180
     f inspect.
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1181
     (Image fromForm:f) inspect
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1182
    "
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1183
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
  1184
    "Modified: 11.7.1996 / 11:21:42 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1185
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1186
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1187
fromImage:anImage
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1188
    "create & return an Image given another image. This can be used to
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1189
     convert an image to another depth."
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1190
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1191
    ^ self fromImage:anImage photometric:nil
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1192
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1193
    "
3448
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1194
     |i i2 idx|
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1195
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1196
     i := Image fromFile:'/home/cg/work/stx/goodies/bitmaps/xpmBitmaps/QUESTION.xpm'.
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1197
     i2 := i deepCopy.
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1198
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1199
     idx := i2 colorMap indexOfPaintNearest:(Color green).
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1200
     i2 colorMap at:idx put:Color red.
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1201
     i2 inspect.
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1202
     i inspect.
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1203
    "
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1204
!
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1205
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1206
fromImage:anImage photometric:photometricOrNil
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1207
    "create & return an Image given another image. This can be used to
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1208
     convert an image to another depth."
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1209
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1210
    (self == Image
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1211
    or:[anImage class == self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1212
        and:[photometricOrNil isNil or:[photometricOrNil == anImage photometric]]]) ifTrue:[^ anImage].
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1213
    ^ self new fromImage:anImage photometric:photometricOrNil.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1214
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1215
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1216
     |i1 i8|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1217
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  1218
     i1 := Image fromFile:'goodies/bitmaps/SBrowser.xbm'.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1219
     i8 := Depth8Image fromImage:i1.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1220
     i8 inspect
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1221
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1222
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1223
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1224
fromSubForm:aRectangle in:aForm
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1225
    "create & return an subImage given a aForm"
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1226
7271
3d35b4e39ec4 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7242
diff changeset
  1227
    |depth formsDevice vis img photometric|
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1228
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1229
    depth := aForm depth.
7271
3d35b4e39ec4 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7242
diff changeset
  1230
    formsDevice := aForm device.
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1231
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1232
    photometric := (depth > 8) ifTrue:[#rgb] ifFalse:[#palette].
4937
1b0ebaed9336 photometric fix
Claus Gittinger <cg@exept.de>
parents: 4893
diff changeset
  1233
7271
3d35b4e39ec4 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7242
diff changeset
  1234
    (formsDevice notNil and:[depth == formsDevice depth]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1235
        "/
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1236
        "/ for truecolor displays, return a Depth24Image
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1237
        "/ (must do this for depth15 & depth16 displays, since
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1238
        "/  Depth16Image has no way to specify r/g/b masks ...)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1239
        "/
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1240
        vis := formsDevice visualType.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1241
        (vis == #TrueColor or:[vis == #DirectColor]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1242
            depth > 8 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1243
                depth := 24.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1244
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1245
        ].
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1246
    ].
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1247
    img := self newForDepth:depth.
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1248
    img photometric:photometric.
4937
1b0ebaed9336 photometric fix
Claus Gittinger <cg@exept.de>
parents: 4893
diff changeset
  1249
7271
3d35b4e39ec4 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7242
diff changeset
  1250
    formsDevice isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1251
        ^ img from:aForm in:aRectangle.
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1252
    ].
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1253
    ^ img from:aForm in:aRectangle
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1254
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1255
    "
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1256
     |f|
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1257
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1258
     f := Form width:16 height:16.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1259
     f clear.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1260
     f displayLineFromX:0 y:0 toX:15 y:15.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1261
     f inspect.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1262
     (Image fromForm:f) inspect.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1263
     (Image fromSubForm:(5@5 corner:10@10) in:f) inspect
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1264
    "
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1265
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1266
    "
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1267
     |f|
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1268
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1269
     f := Form width:16 height:16 depth:(Display depth) on:Display.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1270
     f clear.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1271
     f paint:(Color red).
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1272
     f displayLineFromX:0 y:0 toX:15 y:15.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1273
     f paint:(Color green).
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1274
     f displayLineFromX:15 y:0 toX:0 y:15.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1275
     f inspect.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1276
     (Image fromForm:f) inspect.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1277
     (Image fromSubForm:(5@5 corner:10@10) in:f) inspect
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1278
    "
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1279
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1280
    "Modified: / 31-01-2017 / 15:03:17 / stefan"
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1281
!
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1282
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1283
fromSubImage:anImage in:aRectangle
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1284
    "create & return an Image from a rectangular area in another image.
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1285
     This can also be used to get a subimage in another depth.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1286
     As with layouts, the rectangle may contain integers (= nr of pixels) or float numbers (= relative size).
7373
61933c223183 added metaData instVar (for free use by image reader)
Claus Gittinger <cg@exept.de>
parents: 7363
diff changeset
  1287
     Color precision may be lost, if conversion is from a higher depth image.
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1288
     For palette & rgb images, this may fail if a color cannot be represented."
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1289
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1290
    |cls|
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1291
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1292
    self == Image ifTrue:[
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  1293
        cls := self implementorForDepth:anImage depth.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1294
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1295
        cls := self.
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1296
    ].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1297
    ^ cls new fromSubImage:anImage in:aRectangle.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1298
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1299
    "
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1300
     |i1 i8|
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1301
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1302
     i1 := Image fromFile:'bitmaps/gifImages/garfield.gif' inPackage:'stx:goodies'.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1303
     i8 := Depth8Image fromSubImage:i1 in:(250@90 extent:50@50).
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1304
     i8 inspect
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1305
    "
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1306
    "
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1307
     |i1 i8|
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1308
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1309
     i1 := Image fromFile:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1310
     i8 := Image fromSubImage:i1 in:(70@50 extent:50@50).
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1311
     i8 inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1312
    "
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1313
    "
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1314
     |i1 i24|
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1315
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1316
     i1 := Image fromFile:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies'.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1317
     i24 := Depth24Image fromSubImage:i1 in:(70@50 extent:50@50).
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1318
     i24 inspect
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1319
    "
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1320
    "
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1321
     |i1 i24|
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1322
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1323
     i1 := Image fromFile:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies'.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1324
     i1 inspect.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1325
     i24 := Depth24Image fromSubImage:i1 in:(0.25@0.25 extent:0.5@0.5).
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1326
     i24 inspect
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1327
    "
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1328
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  1329
    "Created: / 20-09-1995 / 01:05:43 / claus"
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  1330
    "Modified: / 24-04-1997 / 23:13:02 / cg"
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  1331
    "Modified (format): / 30-01-2017 / 19:45:54 / stefan"
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1332
!
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1333
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1334
new
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1335
    "create a new image. Redefined to set the photometric to
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1336
     greyScale with black being 0 as default."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1337
4416
fb209558d622 proper #initialize
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
  1338
    ^ self basicNew initialize
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1339
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1340
    "Modified: 10.6.1996 / 18:08:37 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1341
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1342
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1343
newForDepth:depth
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1344
    "create a new image. Redefined to set the photometric to
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1345
     greyScale with black being 0 as default."
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1346
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1347
    |cls|
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1348
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1349
    cls := self implementorForDepth:depth.
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1350
    ^ cls new
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1351
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1352
    "
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1353
     Image newForDepth:8
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1354
    "
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1355
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1356
    "Modified: / 27-05-2007 / 16:57:09 / cg"
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1357
!
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1358
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1359
width:w height:h
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1360
    "create a new image, given width, height.
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1361
     Assume a depth of 1, unless an explicit imageClass is the receiver."
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1362
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1363
    |cls|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1364
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1365
    cls := self.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1366
    cls == Image ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1367
        cls := self implementorForDepth:1
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  1368
    ].
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  1369
    ^ cls new width:w height:h
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  1370
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  1371
    "Modified: / 06-06-2007 / 11:10:55 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1372
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1373
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1374
width:w height:h depth:d
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1375
    "create a new image, given width, height and depth"
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1376
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1377
    ^ (self newForDepth:d)
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1378
        width:w height:h depth:d
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1379
!
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1380
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1381
width:w height:h depth:d fromArray:pixelData
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1382
    "create a new image, given width, height, depth and data.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1383
     Data must be a ByteArray containing correctly aligned bits for the specified
134
claus
parents: 132
diff changeset
  1384
     depth (8-bit padded)."
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1385
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1386
    ^ (self newForDepth:d)
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1387
        width:w height:h depth:d fromArray:pixelData
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1388
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1389
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1390
     Image width:8
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1391
           height:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1392
           depth:1
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1393
           fromArray:#[2r11001100
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1394
                       2r00110011
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1395
                       2r11001100
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1396
                       2r00110011
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1397
                       2r11001100
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1398
                       2r00110011
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1399
                       2r11001100
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1400
                       2r00110011].
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1401
    "
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1402
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1403
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1404
     Image width:8
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1405
           height:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1406
           depth:2
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1407
           fromArray:#[4r1100 4r1100
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1408
                       4r0011 4r0011
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1409
                       4r1100 4r1100
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1410
                       4r0011 4r0011
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1411
                       4r1100 4r1100
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1412
                       4r0011 4r0011
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1413
                       4r1100 4r1100
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1414
                       4r0011 4r0011].
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1415
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1416
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1417
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1418
     Image width:8
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1419
           height:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1420
           depth:4
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1421
           fromArray:#[16r00 16r01 16rf0 16rf1
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1422
                       16r02 16r03 16rf2 16rf3
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1423
                       16r04 16r05 16rf4 16rf5
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1424
                       16r06 16r07 16rf6 16rf7
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1425
                       16r08 16r09 16rf8 16rf9
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1426
                       16r0a 16r0b 16rfa 16rfb
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1427
                       16r0c 16r0d 16rfc 16rfd
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1428
                       16r0e 16r0f 16rfe 16rff].
7101
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1429
    "
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1430
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1431
    "
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1432
     Image width:8
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1433
           height:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1434
           depth:16
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1435
           fromArray:#(1 1 1 1 1 1 1 1
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1436
                       2 2 2 2 2 2 2 2
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1437
                       3 3 3 3 3 3 3 3
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1438
                       4 4 4 4 4 4 4 4
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1439
                       5 5 5 5 5 5 5 5
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1440
                       6 6 6 6 6 6 6 6
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1441
                       7 7 7 7 7 7 7 7
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1442
                       8 8 8 8 8 8 8 8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1443
                      ) asWordArray.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1444
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1445
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1446
    "Modified: 10.6.1996 / 18:18:10 / cg"
132
claus
parents: 125
diff changeset
  1447
!
claus
parents: 125
diff changeset
  1448
134
claus
parents: 132
diff changeset
  1449
width:w height:h depth:d fromArray:pixelData pad:padding
claus
parents: 132
diff changeset
  1450
    "create a new image, given width, height, depth and data.
claus
parents: 132
diff changeset
  1451
     Data must be a ByteArray containing correctly aligned bits for the specified
claus
parents: 132
diff changeset
  1452
     depth."
claus
parents: 132
diff changeset
  1453
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1454
    |img newBits
2772
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  1455
     srcRowBytes "{ Class: SmallInteger }"
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  1456
     dstRowBytes "{ Class: SmallInteger }"
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  1457
     nextDstIndex "{ Class: SmallInteger }"
2527
5391e6e2c8a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2526
diff changeset
  1458
     srcIndex "{ Class: SmallInteger }"
5391e6e2c8a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2526
diff changeset
  1459
     dstIndex "{ Class: SmallInteger }" |
134
claus
parents: 132
diff changeset
  1460
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1461
    img := (self newForDepth:d) width:w height:h depth:d .
134
claus
parents: 132
diff changeset
  1462
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1463
    srcRowBytes := ((w * d + padding - 1) bitShift:-5) bitShift:2.
5341
ede63c3764ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5326
diff changeset
  1464
    dstRowBytes := img bytesPerRow.
ede63c3764ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5326
diff changeset
  1465
ede63c3764ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5326
diff changeset
  1466
    (padding ~~ 8 and:[(srcRowBytes \\ 4 ~~ 0) or:[srcRowBytes ~= dstRowBytes]]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1467
        "must repad; ST/X uses byte padding, while ST-80 uses longword
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1468
         padding. This is stupid, and may be changed in ST/X with future versions.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1469
        "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1470
        dstRowBytes := img bytesPerRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1471
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1472
        newBits := ByteArray uninitializedNew:(dstRowBytes * h).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1473
        srcIndex := 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1474
        dstIndex := 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1475
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1476
        1 to:h do:[:row |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1477
            nextDstIndex := dstIndex + dstRowBytes.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1478
            newBits replaceFrom:dstIndex
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1479
                             to:(nextDstIndex - 1)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1480
                           with:pixelData
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1481
                     startingAt:srcIndex.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1482
            srcIndex := srcIndex + srcRowBytes.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1483
            dstIndex := nextDstIndex.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1484
        ].
134
claus
parents: 132
diff changeset
  1485
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1486
        pixelData class isBytes ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1487
            newBits := ByteArray withAll:pixelData
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1488
        ] ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1489
            newBits := pixelData
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1490
        ]
134
claus
parents: 132
diff changeset
  1491
    ].
claus
parents: 132
diff changeset
  1492
    img bits:newBits.
claus
parents: 132
diff changeset
  1493
    ^ img
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1494
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1495
    "Modified: / 27-05-2007 / 14:01:32 / cg"
134
claus
parents: 132
diff changeset
  1496
!
claus
parents: 132
diff changeset
  1497
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1498
width:w height:h fromArray:anArray
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1499
    "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
  1500
     receiving class is Image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1501
     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
  1502
     (i.e. 8 bits per byte)."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1503
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1504
    |cls d pixels|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1505
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1506
    cls := self.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1507
    cls == Image ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1508
        cls := self implementorForDepth:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1509
        d := 1.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1510
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1511
        d := cls imageDepth
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1512
    ].
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1513
    anArray class isBytes ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1514
        pixels := ByteArray withAll:anArray
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1515
    ] ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1516
        pixels := anArray
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1517
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1518
    ^ cls new width:w height:h depth:d fromArray:pixels
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1519
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1520
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1521
     Image width:8
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1522
           height:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1523
           fromArray:#[2r11001100
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1524
                       2r00110011
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1525
                       2r11001100
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1526
                       2r00110011
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1527
                       2r11001100
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1528
                       2r00110011
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1529
                       2r11001100
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1530
                       2r00110011].
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1531
    "
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1532
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1533
    "Modified: 8.6.1996 / 10:07:26 / cg"
6899
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1534
!
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1535
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1536
width:w height:h photometric:photometric
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1537
    "create a new image, given width, height.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1538
     Assume a depth of 1, unless an explicit imageClass is the receiver."
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1539
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1540
    |cls|
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1541
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1542
    cls := self.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1543
    cls == Image ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1544
        cls := self implementorForDepth:1
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1545
    ].
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1546
    ^ cls new width:w height:h; photometric:photometric; yourself
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1547
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1548
    "Modified: / 06-06-2007 / 11:10:55 / cg"
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1549
!
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1550
6899
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1551
width:w height:h photometric:photometric bitsPerSample:bitsPerSample
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1552
    "create a new image, given width, height.
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1553
     Assume a depth of 1, unless an explicit imageClass is the receiver."
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1554
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1555
    |cls|
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1556
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1557
    cls := self.
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1558
    cls == Image ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1559
        cls := self implementorForDepth:1
6899
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1560
    ].
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1561
    ^ cls new width:w height:h; photometric:photometric; bitsPerSample:bitsPerSample; yourself
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1562
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1563
    "Modified: / 06-06-2007 / 11:10:55 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1564
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1565
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1566
!Image class methodsFor:'Signal constants'!
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1567
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1568
badImageFormatQuerySignal
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1569
    "return the (query-) signal, which is raised if some
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1570
     bitmap-image could not be loaded due to an unrecognized format.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1571
     If unhandled, the image-load returns nil.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1572
     Otherwise, it returns whatever the handler proceeds with.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1573
     The exception gets either the images fileName or an input stream
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1574
     as parameter"
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1575
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1576
    ^ BadImageFormatQuerySignal
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1577
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1578
    "Created: 1.2.1997 / 14:40:29 / cg"
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1579
!
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1580
1385
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1581
cannotRepresentImageSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1582
    "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
  1583
     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
  1584
     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
  1585
     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
  1586
     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
  1587
     (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
  1588
     format then."
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1589
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1590
    ^ CannotRepresentImageSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1591
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1592
    "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
  1593
!
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1594
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1595
fileCreationErrorSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1596
    "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
  1597
     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
  1598
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1599
    ^ FileCreationErrorSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1600
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1601
    "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
  1602
!
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1603
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1604
imageErrorSignal
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1605
    "return the parent of all image signals"
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1606
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1607
    ^ ImageErrorSignal
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1608
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1609
    "Created: / 30.9.1998 / 21:59:08 / cg"
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1610
!
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1611
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1612
imageLoadErrorSignal
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1613
    "return the parent of all image load error signals"
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1614
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1615
    ^ ImageLoadErrorSignal
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1616
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1617
    "Created: / 18.5.1999 / 15:42:05 / cg"
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1618
!
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1619
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1620
imageNotFoundQuerySignal
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1621
    "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
  1622
     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
  1623
     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
  1624
     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
  1625
     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
  1626
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1627
    ^ ImageNotFoundQuerySignal
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1628
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1629
    "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
  1630
!
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1631
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1632
imageSaveErrorSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1633
    "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
  1634
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1635
    ^ ImageSaveErrorSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1636
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1637
    "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
  1638
!
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1639
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1640
informationLostQuerySignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1641
    "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
  1642
     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
  1643
     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
  1644
     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
  1645
     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
  1646
     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
  1647
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1648
    ^ InformationLostQuerySignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1649
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1650
    "Created: 27.2.1997 / 12:43:50 / cg"
2182
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1651
!
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1652
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1653
unrepresentableColorSignal
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1654
    "return the signal, which is raised if some color is not
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1655
     representable in the image (when storing a pixel)."
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1656
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1657
    ^ UnrepresentableColorSignal
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1658
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1659
    "Created: 1.2.1997 / 14:40:29 / cg"
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1660
! !
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1661
1230
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1662
!Image class methodsFor:'cleanup'!
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1663
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1664
releaseResourcesOnDevice:aDevice
1230
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1665
    "this is sent when a display connection is closed,
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1666
     to release all cached Images from that device"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1667
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1668
    Lobby
7565
462e6f62c737 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 7552
diff changeset
  1669
        unregisterAllForWhichHandle:[:eachImage |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1670
            |ok|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1671
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1672
            ok := eachImage graphicsDevice == aDevice.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1673
            ok ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1674
                eachImage releaseFromDevice
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1675
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1676
            ok
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1677
        ].
6390
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
  1678
7573
656c59bc93ad #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7565
diff changeset
  1679
    Icon notNil ifTrue:[
656c59bc93ad #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7565
diff changeset
  1680
        Icon releaseCachedIconsFromDevice:aDevice.
656c59bc93ad #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7565
diff changeset
  1681
    ].
656c59bc93ad #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7565
diff changeset
  1682
    MenuPanel notNil ifTrue:[
656c59bc93ad #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7565
diff changeset
  1683
        MenuPanel releaseCachedImagesFromDevice:aDevice.
656c59bc93ad #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7565
diff changeset
  1684
    ].
656c59bc93ad #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7565
diff changeset
  1685
656c59bc93ad #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7565
diff changeset
  1686
6390
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
  1687
    "
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
  1688
      self releaseResourcesOnDevice:Screen current
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
  1689
    "
1230
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1690
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1691
    "Created: 16.1.1997 / 19:30:44 / cg"
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1692
    "Modified: 16.1.1997 / 19:33:49 / cg"
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1693
! !
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1694
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  1695
!Image class methodsFor:'file reading'!
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1696
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1697
fromFile:aFileName
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1698
    "read an image from a file - this methods tries to find
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1699
     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
  1700
     and lets the appropriate reader read the file.
6375
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1701
     Also, unless the path is absolute,
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1702
     all bitmap directories along the searchPath are checked
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1703
     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
  1704
     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
  1705
     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
  1706
     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
  1707
     proceed with some replacement image. If unhandled, nil is returned."
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1708
6532
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1709
    |image fn nm inStream suffix readerClass
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1710
     mustDecompress readersErrorMsg|
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1711
4159
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1712
    "before trying each reader, check if the file is readable"
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1713
6532
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1714
    fn := aFileName asFilename.
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1715
    fn isAbsolute ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1716
        inStream := Smalltalk systemFileStreamFor:fn.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1717
        inStream isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1718
            inStream := Smalltalk bitmapFileStreamFor:fn.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1719
            inStream isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1720
                "this signal is a query - if noone seems to care, return nil.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1721
                 However, a handler may provide a replacement image."
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1722
                ^ ImageNotFoundQuerySignal
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1723
                            raiseRequestWith:fn
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1724
                            errorString:('Image: ''' , fn pathName, ''' does not exist or is not readable').
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1725
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1726
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1727
        fn := inStream pathName asFilename.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1728
        inStream close.
4843
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1729
    ].
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1730
4158
930761d24ab2 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4156
diff changeset
  1731
    nm := fn name.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1732
    suffix := fn suffix.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1733
4159
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1734
    "handle compressed-suffix"
6532
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1735
    (#('gz') includes:suffix) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1736
        |baseFn|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1737
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1738
        baseFn := fn withoutSuffix.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1739
        nm := baseFn name.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1740
        suffix := baseFn suffix.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1741
        mustDecompress := true.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1742
    ].
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1743
    suffix isEmpty ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1744
        suffix := nm.
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
  1745
    ].
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
  1746
6507
05fb9b9d9e53 class: Image
Claus Gittinger <cg@exept.de>
parents: 6496
diff changeset
  1747
    "get the imageReader class from the file's extension and ask it first"
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  1748
    readerClass := MIMETypes imageReaderForSuffix:suffix.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1749
    readerClass notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1750
        mustDecompress == true ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1751
            |zipStream|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1752
            inStream := fn readStream.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1753
            zipStream := ZipStream readOpenOn:inStream suppressHeaderAndChecksum:true.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1754
            zipStream notNil ifTrue:[
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  1755
                image := [
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  1756
                    readerClass fromStream:zipStream.
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1757
                ] ensure:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1758
                    zipStream close.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1759
                    inStream close.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1760
                ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1761
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1762
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1763
            BadImageFormatQuerySignal handle:[:ex |
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1764
                BadImageFormatQuerySignal isHandled ifTrue:[
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1765
                    ex reject
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1766
                ].
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1767
                readersErrorMsg := ex description.
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1768
                Logger warning:readersErrorMsg.
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1769
                image := nil.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1770
                ex return.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1771
            ] do:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1772
                image := readerClass fromFile:fn.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1773
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1774
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1775
        image notNil ifTrue:[^ image].
4159
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1776
    ].
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1777
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1778
    (readerClass isNil or:[readersErrorMsg notNil]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1779
        "no known extension (or wrong extension)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1780
         - ask all readers if they know this format ...
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1781
         ... these look into the file, and investigate the header.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1782
         therefore, it takes a bit longer."
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1783
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1784
        MIMETypes imageReaderClasses do:[:mimeReaderClass |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1785
            (mimeReaderClass notNil
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1786
            and:[mimeReaderClass ~~ readerClass]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1787
               (mimeReaderClass isValidImageFile:fn) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1788
                    image := mimeReaderClass fromFile:fn.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1789
                    image notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1790
                        ^ image
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1791
                    ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1792
                ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1793
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1794
        ].
4159
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1795
    ].
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1796
7175
4bd37cf4075e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7173
diff changeset
  1797
    (fn exists and:[fn isReadable]) ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1798
        ^ ImageNotFoundQuerySignal
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1799
                    raiseRequestWith:fn
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1800
                    errorString:('Image: ''' , fn pathName, ''' does not exist or is not readable').
7373
61933c223183 added metaData instVar (for free use by image reader)
Claus Gittinger <cg@exept.de>
parents: 7363
diff changeset
  1801
    ].
61933c223183 added metaData instVar (for free use by image reader)
Claus Gittinger <cg@exept.de>
parents: 7363
diff changeset
  1802
4159
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1803
    "nope - unknown format
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1804
     this signal is a query - if noone seems to care, return nil.
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1805
     However, a handler may provide a replacement image."
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1806
3656
11670e0e6fcb invalid format notification fixed
Claus Gittinger <cg@exept.de>
parents: 3623
diff changeset
  1807
    ^ BadImageFormatQuerySignal
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1808
        raiseRequestWith:fn
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1809
        errorString:(readersErrorMsg ? ('Image: unknown image file format: ''' , fn pathName , '''')).
4159
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1810
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1811
    "
6532
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1812
     Image fromFile:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies'
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1813
     Image fromFile:'bitmaps/gifImages/garfield.gif' inPackage:'stx:goodies'
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1814
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1815
     Image fromFile:'bitmaps/winBitmaps/a11.ico' inPackage:'stx:goodies'
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1816
     Image fromFile:'bitmaps/xpmBitmaps/countries/czech.xpm' inPackage:'stx:goodies'
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1817
     Image fromFile:'bitmaps/xpmBitmaps/countries/czech.xpm.gz' inPackage:'stx:goodies'
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1818
     Image fromFile:'Demos/bitmaps/hello_world.icon' inPackage:'stx:clients'
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1819
    "
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1820
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1821
    "
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1822
     Image fromFile:'fooBar'
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1823
    "
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1824
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
  1825
    "giving a message for non-existing images:
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1826
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1827
     Image imageNotFoundQuerySignal
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1828
     handle:[:ex |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1829
        Transcript showCR:ex description.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1830
        ex proceedWith:nil
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1831
     ] do:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1832
         Image fromFile:'fooBar'
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1833
     ]
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1834
    "
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1835
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1836
    "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
  1837
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1838
     Image imageNotFoundQuerySignal
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
  1839
     answer:(Image fromFile:'libtool/bitmaps/SmalltalkX.xbm')
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1840
     do:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1841
         Image fromFile:'fooBar'
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1842
     ]
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1843
    "
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1844
4843
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1845
    "Modified: / 19-11-2007 / 15:50:52 / cg"
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1846
    "Modified: / 31-01-2017 / 15:56:14 / stefan"
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1847
!
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1848
3426
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1849
fromFile:aFileName inPackage:aPackage
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1850
    "read an image for a package from a file.
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1851
     The filename is assumed to be package-relative (i.e. bitmaps/filename).
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1852
     This methods tries to find out the file format itself (by the extension and by contents)
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1853
     and lets the appropriate reader read the file.
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1854
     Also, all bitmap directories along the searchPath are checked
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1855
     for the file; thus, you can place your private images into a
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1856
     separate directory, thereby overriding system bitmaps easily.
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1857
     If the file is unreadable or does not contain an appropriate image,
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1858
     the ImageNotFoundQuerySignal is raised, which may be handled to
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1859
     proceed with some replacement image. If unhandled, nil is returned."
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1860
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1861
    ^ Smalltalk imageFromFileNamed:aFileName inPackage:aPackage
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1862
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1863
    "
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1864
     Image fromFile:'libtool/bitmaps/SBrowser.xbm'
3426
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1865
     Image fromFile:'bitmaps/SBrowser.xbm' inPackage:'stx:libtool'
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1866
     Image fromFile:'garfield.gif' inPackage:'stx:goodies/bitmaps/gifImages'
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1867
    "
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1868
!
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1869
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1870
fromFile:aFileName on:aDevice
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1871
    "read an image from a file and prepare a device representation.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1872
     Return nil (or whatever a handler returned),
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1873
     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
  1874
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1875
    |img|
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1876
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1877
    img := self fromFile:aFileName.
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1878
    img notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1879
        ^ img onDevice:aDevice
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1880
    ].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1881
    ^ nil
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1882
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1883
    "Modified: 1.2.1997 / 14:48:07 / cg"
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1884
!
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1885
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1886
fromFile:aFileName resolution:res
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1887
    "read an image from a file and (if required) scale the image
3059
0895d23678ac assume 90dpi in #fromFile:resolution: if there is no current display
Claus Gittinger <cg@exept.de>
parents: 3038
diff changeset
  1888
     as appropriate (only req'd for very high resolution displays).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1889
     Return nil (or whatever a handler returned),
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1890
     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
  1891
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1892
    ^ self fromFile:aFileName resolution:res on:nil
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1893
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1894
    "Created: 19.12.1996 / 14:02:13 / cg"
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1895
    "Modified: 1.2.1997 / 14:48:16 / cg"
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1896
!
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1897
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1898
fromFile:aFileName resolution:dpi on:aDevice
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1899
    "read an image from a file and (if required) scale the image
3059
0895d23678ac assume 90dpi in #fromFile:resolution: if there is no current display
Claus Gittinger <cg@exept.de>
parents: 3038
diff changeset
  1900
     as appropriate (only req'd with very high resolution displays).
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1901
     Prepare a device representation.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1902
     Return nil (or whatever a handler returned),
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1903
     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
  1904
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1905
    |img dev dpiH mag|
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1906
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1907
    img := self fromFile:aFileName.
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1908
    img isNil ifTrue:[^ nil].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1909
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1910
    "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
  1911
    dev := aDevice.
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1912
    dev isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1913
        "should not happen ..."
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1914
        dev := Screen current
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1915
    ].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1916
3059
0895d23678ac assume 90dpi in #fromFile:resolution: if there is no current display
Claus Gittinger <cg@exept.de>
parents: 3038
diff changeset
  1917
    dev notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1918
        dpiH := dev horizontalPixelPerInch.
3059
0895d23678ac assume 90dpi in #fromFile:resolution: if there is no current display
Claus Gittinger <cg@exept.de>
parents: 3038
diff changeset
  1919
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1920
        dpiH := 90
3059
0895d23678ac assume 90dpi in #fromFile:resolution: if there is no current display
Claus Gittinger <cg@exept.de>
parents: 3038
diff changeset
  1921
    ].
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1922
    (dpi between:(dpiH * 0.75) and:(dpiH * 1.5)) ifTrue:[
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1923
        ^ img
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1924
    ].
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1925
    mag := (dpiH / dpi) rounded.
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1926
    mag = 0 ifTrue:[^ img].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1927
    mag = 1 ifTrue:[^ img].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1928
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1929
    img := img magnifiedBy:(mag @ mag).
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1930
    aDevice notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1931
        ^ img onDevice:aDevice
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1932
    ].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1933
    ^ img
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1934
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1935
    "Modified: / 01-02-1997 / 14:48:20 / cg"
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1936
    "Modified (format): / 31-01-2017 / 15:06:23 / stefan"
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1937
!
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1938
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1939
fromStream:aStream
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1940
    "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
  1941
     out the file format itself (by contents)
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1942
     and lets the appropriate reader read the file.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1943
     To do this, the stream must be positionable.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1944
     Return nil (or whatever a handler returned),
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1945
     if the stream does not contain an appropriate image."
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1946
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  1947
    |image|
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1948
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1949
    "
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1950
     ask all readers if they know
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1951
     this format ...
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1952
    "
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  1953
    MIMETypes imageReaderClasses do:[:readerClass |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1954
        readerClass notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1955
            image := readerClass fromStream:aStream.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1956
            image notNil ifTrue:[^ image].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1957
        ]
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1958
    ].
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1959
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1960
    "
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1961
     nope - unknown format
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1962
    "
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1963
"/    'Image [info]: unknown image file format in stream: ' infoPrintCR.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1964
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1965
    ^ ImageNotFoundQuerySignal
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1966
                raiseRequestWith:aStream
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1967
                errorString:('Image [warning]: unknown image file format in stream').
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1968
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1969
    "
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1970
     Image fromFile:'goodies/bitmaps/gifImages/claus.gif'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1971
     Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1972
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1973
     Image fromFile:'clients/Animation/bitmaps/globe1.xbm'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1974
     Image fromFile:'clients/Animation/bitmaps/globe1.xbm.Z'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1975
     Image fromFile:'clients/Demos/bitmaps/hello_world.icon'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1976
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1977
     Image fromFile:'librun/stx.ico'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1978
     Image fromFile:'libwidg3/bitmaps/wall.tiff'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1979
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  1980
     Image fromFile:'goodies/bitmaps/test.fax'
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1981
     Image fromFile:'fileIn/bitmaps/founders.im8'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1982
     Image fromFile:'goodies/faces/next.com/steve.face'
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1983
    "
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1984
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1985
    "Created: 13.9.1996 / 18:06:00 / cg"
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  1986
    "Modified: 30.6.1997 / 22:03:59 / cg"
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1987
!
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1988
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1989
fromStream:aStream using:aReaderClass
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1990
    "read an image from a stream, given an imageReaderClass.
6507
05fb9b9d9e53 class: Image
Claus Gittinger <cg@exept.de>
parents: 6496
diff changeset
  1991
     Use this, if you know the file's format, but it has an invalid
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1992
     extension (or non-definite header), so #fromStream: could not
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1993
     find out the images format.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1994
     Return nil (or whatever a handler returned),
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1995
     if the stream does not contain an appropriate image."
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1996
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1997
    |image|
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1998
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1999
    image := aReaderClass fromStream:aStream.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2000
    image notNil ifTrue:[^ image].
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2001
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2002
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2003
     nope - unknown format
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2004
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2005
"/    'Image [info]: unknown image file format in stream: ' infoPrintCR.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2006
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2007
    ^ ImageNotFoundQuerySignal
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2008
                raiseRequestWith:aStream
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2009
                errorString:('Image: unknown image file format in stream').
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2010
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2011
    "Created: 1.2.1997 / 14:46:20 / cg"
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2012
    "Modified: 1.2.1997 / 14:48:53 / cg"
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  2013
! !
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  2014
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  2015
!Image class methodsFor:'misc'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2016
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  2017
ditherAlgorithm
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2018
    "return the way we dither -
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2019
        #threshold, or nil        -> no dither
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2020
        #pattern, or #ordered     -> orderedDither (ugly, but fast)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2021
        #error or #floydSteinberg -> errorDiffusion; much better
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2022
        #burkes                   -> errorDiffusion; even better."
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  2023
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  2024
    ^ DitherAlgorithm
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  2025
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  2026
    "Created: 17.6.1996 / 18:57:47 / cg"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  2027
!
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  2028
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  2029
ditherAlgorithm:aSymbol
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2030
    "define how to dither -
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2031
        #threshold, or nil        -> no dither
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2032
        #pattern, or #ordered     -> orderedDither (ugly, but fast)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2033
        #error or #floydSteinberg -> errorDiffusion; much better
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2034
        #burkes                   -> errorDiffusion; even better."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2035
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2036
    DitherAlgorithm := aSymbol
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2037
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2038
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2039
     Image dither:#pattern
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2040
     Image dither:#floydSteinberg
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2041
     Image dither:#burkes
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2042
     Image dither:nil
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2043
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2044
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2045
    "Modified: 10.6.1996 / 12:27:09 / cg"
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  2046
    "Created: 17.6.1996 / 18:57:19 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2047
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2048
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2049
numberOfDitherColors:n
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2050
    "define how many colors (i.e. patterns) to use when
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2051
     doing a pattern dither"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2052
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2053
    NumberOfDitherColors := n
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2054
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2055
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2056
orderedDitherMatrixOfSize:sz
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2057
    sz == 2 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2058
        ^ #[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2059
                0 2
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2060
                3 1
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2061
           ].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2062
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2063
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2064
    sz == 4 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2065
        ^ #[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2066
                 0  8  2 10
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2067
                12  4 14  6
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2068
                 3 11  1  9
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2069
                15  7 13  5
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2070
           ].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2071
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2072
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2073
    sz == 8 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2074
        ^  #[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2075
                0 32  8 40    2 34 10 42
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2076
               48 16 56 24   50 18 58 26
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2077
               12 44  4 36   14 46  6 38
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2078
               60 28 52 20   62 30 54 22
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2079
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2080
                3 35 11 43    1 33  9 41
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2081
               51 19 59 27   49 17 57 25
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2082
               15 47  7 39   13 45  5 37
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2083
               63 31 55 23   61 29 53 21
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2084
            ].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2085
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2086
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2087
    ^ nil
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2088
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2089
    "Created: 7.6.1996 / 14:15:05 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2090
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2091
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  2092
!Image class methodsFor:'queries'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2093
2005
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2094
bytesPerRowForWidth:width depth:bitsPerPixel padding:padding
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2095
    "helper - return the number of bytes in one scanline of an image,
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2096
     if scanlines are to be padded to padding-bits and the depth of the image is d."
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2097
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2098
    |bitsPerRow paddedUnitsPerRow|
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2099
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2100
    bitsPerRow := width * bitsPerPixel.
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2101
    paddedUnitsPerRow := bitsPerRow // padding.
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2102
    ((bitsPerRow \\ padding) ~~ 0) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2103
        paddedUnitsPerRow := paddedUnitsPerRow + 1
2005
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2104
    ].
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2105
    ^ paddedUnitsPerRow * (padding // 8)
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2106
5126
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  2107
    "
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  2108
     self bytesPerRowForWidth:7 depth:1 padding:8
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  2109
     self bytesPerRowForWidth:7 depth:1 padding:16
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  2110
     self bytesPerRowForWidth:7 depth:1 padding:32
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  2111
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  2112
     self bytesPerRowForWidth:15 depth:1 padding:8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  2113
     self bytesPerRowForWidth:15 depth:1 padding:16
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  2114
     self bytesPerRowForWidth:15 depth:1 padding:32
5126
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  2115
    "
2005
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2116
!
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2117
6797
161685b0d113 class: Image
Claus Gittinger <cg@exept.de>
parents: 6755
diff changeset
  2118
defaultImageFileWriter
161685b0d113 class: Image
Claus Gittinger <cg@exept.de>
parents: 6755
diff changeset
  2119
    "only used, if a file is saved with no particular extension
161685b0d113 class: Image
Claus Gittinger <cg@exept.de>
parents: 6755
diff changeset
  2120
     or explicit writer given.
161685b0d113 class: Image
Claus Gittinger <cg@exept.de>
parents: 6755
diff changeset
  2121
     For now, default to tiff format.
161685b0d113 class: Image
Claus Gittinger <cg@exept.de>
parents: 6755
diff changeset
  2122
     Will change to png, as soon as all mask formats are fully supported by it"
161685b0d113 class: Image
Claus Gittinger <cg@exept.de>
parents: 6755
diff changeset
  2123
161685b0d113 class: Image
Claus Gittinger <cg@exept.de>
parents: 6755
diff changeset
  2124
    ^ TIFFReader
161685b0d113 class: Image
Claus Gittinger <cg@exept.de>
parents: 6755
diff changeset
  2125
!
161685b0d113 class: Image
Claus Gittinger <cg@exept.de>
parents: 6755
diff changeset
  2126
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2127
defaultPhotometric
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  2128
    "return the default photometric pixel interpretation.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  2129
     This may be a somewhat old leftover from times, when tiff was the first image file type to be read.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  2130
     Much better would be to always have some (possibly fake and virtual) colormap around, and ask that one.
7373
61933c223183 added metaData instVar (for free use by image reader)
Claus Gittinger <cg@exept.de>
parents: 7363
diff changeset
  2131
     However, in the meantime, many other classes depend on that, so that it should be kept as an API
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  2132
     - even when the internal representation will be replaced by something better in the future."
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2133
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2134
    ^ #blackIs0
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2135
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2136
    "Modified: 20.4.1996 / 23:40:41 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2137
    "Created: 10.6.1996 / 18:08:12 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2138
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2139
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2140
imageDepth
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2141
    "return the depth of images represented by instances of
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2142
     this class.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2143
     Must be redefined in concrete subclasses"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2144
2913
c51ac85e9aa2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2891
diff changeset
  2145
    ^ self subclassResponsibility
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2146
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2147
    "Modified: 20.4.1996 / 23:40:41 / cg"
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  2148
!
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  2149
1306
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  2150
imageFileSuffixes
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  2151
    "return a collection of suffixes which are recognized as image-file suffix"
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  2152
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  2153
    ^ MIMETypes imageFileSuffixes
1306
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  2154
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  2155
    "
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  2156
     Image imageFileSuffixes
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  2157
    "
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  2158
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  2159
    "Modified: 30.6.1997 / 22:04:39 / cg"
1306
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  2160
!
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  2161
1783
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2162
imageReaderClassForMIME:mimeType
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2163
    "return an appropriate imageReader class for a given mime type;
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2164
     nil if there is none (or it did not install itself)"
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2165
1801
3dff7fb2bd59 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1800
diff changeset
  2166
    ^ MIMETypes imageReaderForType:mimeType
1783
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2167
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2168
    "
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2169
     Image imageReaderClassForMIME:'image/tiff'
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2170
     Image imageReaderClassForMIME:'image/x-portable-pixmap'
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2171
    "
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2172
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2173
    "Created: 24.6.1997 / 22:32:27 / cg"
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  2174
    "Modified: 30.6.1997 / 21:54:10 / cg"
1783
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2175
!
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2176
1572
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  2177
imageReaderClassForSuffix:aSuffix
1783
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2178
    "return an appropriate imageReader class for a given file-suffix;
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2179
     nil if there is none (or it did not install itself)"
1572
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  2180
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  2181
    ^ MIMETypes imageReaderForSuffix:aSuffix
1572
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  2182
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  2183
    "
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  2184
     Image imageReaderClassForSuffix:'tiff'
1783
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2185
     Image imageReaderClassForSuffix:'foo'
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2186
    "
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2187
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  2188
    "Modified: 30.6.1997 / 22:05:14 / cg"
1572
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  2189
!
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  2190
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  2191
implementorForDepth:depth
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2192
    "return the class, which best implements images of depth"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2193
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2194
    depth == 1 ifTrue:[^ Depth1Image].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2195
    depth == 2 ifTrue:[^ Depth2Image].
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  2196
    depth <= 4 ifTrue:[^ Depth4Image].
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  2197
    depth <= 8 ifTrue:[^ Depth8Image].
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  2198
    depth <= 16 ifTrue:[^ Depth16Image].
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  2199
    depth <= 24 ifTrue:[^ Depth24Image].
1664
42b1af0353c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1662
diff changeset
  2200
    depth <= 32 ifTrue:[^ Depth32Image].
5299
6b1d1dcf5c85 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5237
diff changeset
  2201
    depth <= 48 ifTrue:[^ Depth48Image].
5313
7c40ea0163ee *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
  2202
    depth <= 64 ifTrue:[^ Depth64Image].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2203
    ^ self
1664
42b1af0353c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1662
diff changeset
  2204
42b1af0353c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1662
diff changeset
  2205
    "Modified: 24.4.1997 / 19:04:52 / cg"
1611
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2206
!
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2207
7795
490b3691a124 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7755
diff changeset
  2208
isAbstract
490b3691a124 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7755
diff changeset
  2209
    ^ self == Image
490b3691a124 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7755
diff changeset
  2210
!
490b3691a124 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7755
diff changeset
  2211
1611
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2212
isImageFileSuffix:aSuffix
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2213
    "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
  2214
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2215
     ^ self imageFileSuffixes includes:(aSuffix asLowercase)
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2216
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2217
    "
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2218
     Image isImageFileSuffix:'gif'
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2219
     Image isImageFileSuffix:'xbm'
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2220
     Image isImageFileSuffix:'foo'
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2221
    "
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2222
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2223
    "Created: 18.4.1997 / 14:55:28 / cg"
1786
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2224
!
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2225
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2226
mimeTypeFromSuffix:suffix
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2227
    "search my suffix information for a mime type and
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2228
     return it; return nil if unknown"
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2229
1802
9a3d7c669727 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2230
    ^ MIMETypes mimeTypeForSuffix:suffix
1786
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2231
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2232
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2233
     Image mimeTypeFromSuffix:'gif'
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2234
     Image mimeTypeFromSuffix:'tiff'
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2235
     Image mimeTypeFromSuffix:'foobar'
1786
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2236
    "
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2237
1802
9a3d7c669727 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2238
    "Modified: 1.7.1997 / 00:17:27 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2239
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2240
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  2241
!Image class methodsFor:'screen capture'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2242
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2243
fromScreen
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2244
    "return an image of the full screen.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2245
     WARNING: this temporarily grabs the display
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2246
              it may not work from within a buttonMotion
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2247
              (use #fromScreen:on:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2248
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2249
    |display|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2250
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2251
    display := Screen current.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2252
    ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2253
        fromScreen:(0@0 corner:(display width @ display height))
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2254
        on:display
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2255
        grab:true
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2256
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2257
    "
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2258
     Image fromScreen
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2259
     Image fromScreen inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2260
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2261
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2262
    "Modified: 26.3.1997 / 10:44:55 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2263
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2264
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2265
fromScreen:aRectangle
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2266
    "return an image of a part of the screen.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2267
     WARNING: this temporarily grabs the display
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2268
              it may not work from within a buttonMotion
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2269
              (use #fromScreen:on:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2270
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2271
    ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2272
        fromScreen:aRectangle
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2273
        on:Screen current
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2274
        grab:true
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2275
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2276
    "
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2277
     Image fromScreen:(0@0 corner:100@100)
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2278
     (Image fromScreen:(0@0 corner:100@100)) inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2279
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2280
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2281
    "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
  2282
!
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2283
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2284
fromScreen:aRectangle on:aDevice
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2285
    "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
  2286
     another display device.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2287
     WARNING: this temporarily grabs the display
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2288
              it may not work from within a buttonMotion
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2289
              (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
  2290
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2291
    ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2292
        fromScreen:aRectangle
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2293
        on:aDevice
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2294
        grab:true
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2295
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2296
    "
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2297
     Image fromScreen:(0@0 corner:100@100)
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2298
    "
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2299
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2300
    "get a snapshot of your friends screen ...
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2301
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2302
     |dpy2|
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2303
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2304
     dpy2 := XWorkstation new initializeFor:'idefix:0'.
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2305
     (Image fromScreen:(dpy2 bounds) on:dpy2) inspect
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2306
    "
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2307
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2308
    "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
  2309
!
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2310
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2311
fromScreen:aRectangle on:aDisplay grab:doGrab
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2312
    "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
  2313
     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
  2314
     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
  2315
     shown while the readout is done.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2316
     WARNING: with doGrab true, this temporarily grabs the display
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2317
              and it may not work from within a buttonMotion
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2318
              (use with a false grabArg then)."
7230
71910d55d08c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7227
diff changeset
  2319
71910d55d08c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7227
diff changeset
  2320
    |depth vis img tmpFile util|
71910d55d08c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7227
diff changeset
  2321
71910d55d08c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7227
diff changeset
  2322
    aDisplay supportsScreenReading ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2323
        "/ workaround: look for a helper utility in support/<os>/screenshot
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2324
        "/ currently there is one for osx.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2325
        tmpFile := Filename newTemporary withSuffix:'png'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2326
        util := Smalltalk packageDirectory asFilename / ('../support/',OperatingSystem getSystemType,'/screenshot').
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2327
        util exists ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2328
            OperatingSystem executeCommand:('%1 %2 png %3 %4 %5 %6'
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2329
                                                bindWith:util pathName
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2330
                                                with:tmpFile pathName
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2331
                                                with:aRectangle left
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2332
                                                with:aRectangle top
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2333
                                                with:aRectangle width
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2334
                                                with:aRectangle height).
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  2335
            ^ [
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  2336
                Image fromFile:tmpFile.
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2337
            ] ensure:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2338
                tmpFile remove.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2339
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2340
        ].
7230
71910d55d08c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7227
diff changeset
  2341
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2342
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2343
    depth := aDisplay depth.
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2344
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2345
    "/
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2346
    "/ 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
  2347
    "/ (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
  2348
    "/  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
  2349
    "/
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2350
    vis := aDisplay visualType.
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2351
    (vis == #TrueColor or:[vis == #DirectColor]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2352
        depth > 8 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2353
            depth := 24.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2354
        ]
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2355
    ].
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2356
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  2357
    img := self newForDepth:depth.
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2358
    ^ img fromScreen:aRectangle on:aDisplay grab:doGrab
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2359
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  2360
    "Modified: / 26-01-1998 / 22:23:08 / cg"
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  2361
    "Modified: / 30-01-2017 / 19:49:01 / stefan"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2362
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2363
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2364
fromScreenArea
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2365
    "return an image of a part of the screen;
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2366
     let user specify screen area.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2367
     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
  2368
     Use #fromUser for ST-80 compatibility.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2369
     WARNING: this temporarily grabs the display
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2370
              it may not work from within a buttonMotion
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2371
              (use #fromScreen:on:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2372
2102
7c7d11aa956e care for empty rectangle in Image>>fromScreenArea
Claus Gittinger <cg@exept.de>
parents: 2081
diff changeset
  2373
    |r|
7c7d11aa956e care for empty rectangle in Image>>fromScreenArea
Claus Gittinger <cg@exept.de>
parents: 2081
diff changeset
  2374
2323
bf88727c4dee wait until button is released in #fromUser.
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  2375
    [Screen current leftButtonPressed] whileTrue:[Delay waitForSeconds:0.05].
2102
7c7d11aa956e care for empty rectangle in Image>>fromScreenArea
Claus Gittinger <cg@exept.de>
parents: 2081
diff changeset
  2376
    r := Rectangle fromUser.
7c7d11aa956e care for empty rectangle in Image>>fromScreenArea
Claus Gittinger <cg@exept.de>
parents: 2081
diff changeset
  2377
    r width == 0 ifTrue:[^ nil].
7c7d11aa956e care for empty rectangle in Image>>fromScreenArea
Claus Gittinger <cg@exept.de>
parents: 2081
diff changeset
  2378
    r height == 0 ifTrue:[^ nil].
7c7d11aa956e care for empty rectangle in Image>>fromScreenArea
Claus Gittinger <cg@exept.de>
parents: 2081
diff changeset
  2379
    ^ self fromScreen:r
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2380
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2381
    "
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2382
     Image fromScreenArea
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2383
     Image fromScreenArea inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2384
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2385
2323
bf88727c4dee wait until button is released in #fromUser.
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  2386
    "Modified: / 10.9.1998 / 15:59:58 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2387
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2388
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2389
fromUser
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2390
    "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
  2391
     Same as fromScreenArea, for ST-80 compatibility.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2392
     WARNING: this temporarily grabs the display
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2393
              it may not work from within a buttonMotion
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2394
              (use #fromScreen:on:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2395
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2396
    ^ self fromScreenArea
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2397
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2398
    "
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2399
     Image fromUser
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2400
     Image fromUser inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2401
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2402
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2403
    "Modified: 26.3.1997 / 10:45:25 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2404
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2405
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2406
fromView:aView
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2407
    "return an image taken from a views contents as currently
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2408
     on the screen. The returned image has the same depth and photometric
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2409
     as the Display.
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2410
     Notice that for invisible or partial covered views,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2411
     the returned Image is NOT correct.
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2412
     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
  2413
     WARNING: this temporarily grabs the display
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2414
              it may not work from within a buttonMotion
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2415
              (use #fromView:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2416
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2417
    ^ self
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2418
        fromView:aView
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2419
        grab:true
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  2420
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  2421
    "
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2422
     Image fromView:(Launcher allInstances first window topView)
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2423
     Image fromView:(BrowserView allInstances first topView)
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2424
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2425
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2426
    "get a snapshot from whichever view is active:
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2427
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2428
     |active|
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2429
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2430
     active := WindowGroup activeGroup topViews first.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2431
     (Image fromView:active) inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2432
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2433
1043
0688425d02c9 Rename Launcher-->OldLauncher, NewLauncher-->Launcher.
Stefan Vogel <sv@exept.de>
parents: 1041
diff changeset
  2434
    "Modified: 9.9.1996 / 22:41:01 / stefan"
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2435
    "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
  2436
!
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2437
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2438
fromView:aView grab:doGrab
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2439
    "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
  2440
     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
  2441
     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
  2442
     shown while the readout is done.
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2443
     The returned image has the same depth and photometric
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2444
     as the Display.
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2445
     Notice that for invisible or partial covered views,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2446
     the returned Image is NOT correct.
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2447
     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
  2448
     WARNING: with doGrab true, this temporarily grabs the display
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2449
              and it may not work from within a buttonMotion
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2450
              (use with a false grabArg then)."
4540
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2451
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2452
    ^ self fromView:aView grab:doGrab withDecoration:false
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2453
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2454
    "Created: / 26.3.1997 / 10:34:20 / cg"
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2455
    "Modified: / 10.10.2001 / 14:13:29 / cg"
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2456
!
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2457
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2458
fromView:aView grab:doGrab withDecoration:withDecoration
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2459
    "return an image taken from a views contents as currently
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2460
     on the screen, optionally with decoration included.
4540
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2461
     If the doGrab argument is true, the display
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2462
     is grabbed (i.e. blocked for others) and a camera cursor is
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2463
     shown while the readout is done.
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2464
     The returned image has the same depth and photometric
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2465
     as the Display.
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2466
     Notice that for invisible or partial covered views,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2467
     the returned Image is NOT correct.
4540
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2468
     You may want to raise the view before using this method.
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2469
     WARNING: with doGrab true, this temporarily grabs the display
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2470
              and it may not work from within a buttonMotion
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2471
              (use with a false grabArg then)."
4540
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2472
7271
3d35b4e39ec4 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7242
diff changeset
  2473
    |org ext viewsDevice cH bW bH|
3d35b4e39ec4 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7242
diff changeset
  2474
3d35b4e39ec4 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7242
diff changeset
  2475
    viewsDevice := aView graphicsDevice.
3d35b4e39ec4 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7242
diff changeset
  2476
    org := viewsDevice translatePoint:(0@0) fromView:aView toView:nil.
4540
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2477
    ext := aView extent.
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2478
    withDecoration ifTrue:[
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2479
        viewsDevice isWindowsPlatform ifTrue:[
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2480
            cH := viewsDevice captionHeight.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2481
            bW := (viewsDevice getSystemMetrics: #SM_CXFRAME )
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2482
                  "+ ( device getSystemMetrics: #borderFrameWidth )".
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2483
            bH := (viewsDevice getSystemMetrics: #SM_CYFRAME )
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2484
                  " + ( device getSystemMetrics: #borderFrameHeight )".
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2485
            org := org - (bW @ (bH + cH)).
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2486
            ext := ext + ((bW + bW) @ (bH+bH+cH)).
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2487
        ].
4540
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2488
    ].
7271
3d35b4e39ec4 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7242
diff changeset
  2489
    ^ self fromScreen:(org extent:ext) on:viewsDevice grab:doGrab
4540
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2490
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2491
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2492
     Transcript topView raise. (Image fromView:Transcript topView grab:false withDecoration:false) inspect
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2493
     Transcript topView raise. (Image fromView:Transcript topView grab:false withDecoration:true) inspect
4540
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2494
    "
3518
983e7730a905 use new translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents: 3507
diff changeset
  2495
4574
4b65895bbb6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4565
diff changeset
  2496
    "Created: / 26-03-1997 / 10:34:20 / cg"
4b65895bbb6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4565
diff changeset
  2497
    "Modified: / 08-09-2006 / 15:41:41 / cg"
157
claus
parents: 154
diff changeset
  2498
! !
claus
parents: 154
diff changeset
  2499
3880
c4c8268a2d9f method category rename
Claus Gittinger <cg@exept.de>
parents: 3876
diff changeset
  2500
!Image methodsFor:'Compatibility-Squeak'!
3475
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2501
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2502
boundingBox
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2503
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2504
    ^ self bounds
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2505
!
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2506
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2507
colormapIfNeededForDepth:d
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2508
    ^ nil
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2509
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2510
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2511
!
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2512
6308
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2513
colorsFromArray:anArrayOfRGBTriples
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2514
    "for squeak compatibility with ColorForm:
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2515
     set the colorMap from an array of rgb triples, each value being in 0..1."
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2516
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2517
    |newMap|
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2518
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2519
    newMap := Colormap new:anArrayOfRGBTriples size.
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2520
    anArrayOfRGBTriples doWithIndex:[:rgb :i |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2521
        newMap at:i putRGBTriple:rgb
6308
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2522
    ].
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2523
    self colorMap:newMap.
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2524
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2525
    "
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2526
     Depth8Image new
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2527
        colorsFromArray:#( (0.5 0.5 0.5) (0.25 0.0 0.0) (0.0 0.25 0.5))
6308
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2528
    "
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2529
!
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2530
3475
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2531
fill:aRectangle fillColor:aColor
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2532
    "fill the rectangular area specified by aRectangle with the given color"
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2533
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2534
    self fillRectangle:aRectangle withColor:aColor
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2535
!
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2536
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2537
fillBlack:aRectangle
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2538
    "fill the rectangular area specified by aRectangle with the black color"
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2539
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2540
    self fillRectangle:aRectangle withColor:Color black
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2541
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2542
    "
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2543
     |img|
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2544
     img := Image extent:100@100 depth:24.
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2545
     img photometric:#rgb.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2546
     img data:(ByteArray new:100*100*3).
3475
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2547
     img fillWhite:(0@0 corner:100@100).
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2548
     img fillBlack:(10@10 corner:90@90).
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2549
     img inspect.
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2550
    "
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2551
!
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2552
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2553
fillWhite:aRectangle
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2554
    "fill the rectangular area specified by aRectangle with the white color"
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2555
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2556
    self fillRectangle:aRectangle withColor:Color white
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2557
!
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2558
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2559
isTransparentAt:aPoint
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2560
    mask isNil ifTrue:[ ^ false].
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2561
    ^ (mask pixelAt:aPoint) == 0
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2562
! !
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2563
3880
c4c8268a2d9f method category rename
Claus Gittinger <cg@exept.de>
parents: 3876
diff changeset
  2564
!Image methodsFor:'Compatibility-VW'!
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2565
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2566
asCachedImage
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2567
    "return the receiver associated to the current screens device.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2568
     For ST-80 compatibility
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2569
     (ST/X uses Image for both device- and nonDevice-images)"
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2570
2832
793500016a2b #on: -> #onDevice:
Claus Gittinger <cg@exept.de>
parents: 2801
diff changeset
  2571
    ^ self onDevice:Screen current
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2572
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2573
    "Modified: 23.4.1996 / 11:10:32 / cg"
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2574
!
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2575
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2576
asRetainedMedium
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2577
    "return the receiver associated to the current screens device.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2578
     For ST-80 compatibility
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2579
     (ST/X uses Image for both device- and nonDevice-images)"
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2580
2832
793500016a2b #on: -> #onDevice:
Claus Gittinger <cg@exept.de>
parents: 2801
diff changeset
  2581
    ^ self onDevice:Screen current
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2582
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2583
    "Modified: 23.4.1996 / 11:10:32 / cg"
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2584
    "Created: 27.1.1997 / 15:49:08 / cg"
1325
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2585
!
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2586
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2587
bounds:newBounds
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2588
    ^ self
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2589
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2590
    "Created: 10.2.1997 / 12:44:46 / cg"
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2591
!
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2592
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2593
containsPoint:aPoint
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2594
    "in st-80, images are visualComponents ..."
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2595
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2596
    ^ self bounds containsPoint:aPoint
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2597
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2598
    "Created: 6.3.1997 / 15:24:12 / cg"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2599
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2600
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2601
convertToPalette:aColormap renderedBy:anImageRenderer
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2602
    "this does not really mimicri the corresponding ST-80 functionality"
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2603
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2604
    |monoBits convertedImage|
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2605
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2606
    aColormap size == 2 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2607
        anImageRenderer class == OrderedDither ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2608
            monoBits := self orderedDitheredMonochromeBits.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2609
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2610
            monoBits := self floydSteinbergDitheredMonochromeBits.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2611
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2612
        (((aColormap at:1) = Color black)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2613
        and:[(aColormap at:2) = Color white]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2614
            "/ ok
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2615
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2616
            (((aColormap at:1) = Color white)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2617
            and:[(aColormap at:2) = Color black]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2618
                monoBits invert
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2619
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2620
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2621
        convertedImage := Depth1Image width:width height:height fromArray:monoBits.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2622
        convertedImage palette:aColormap.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2623
        ^ convertedImage
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2624
    ].
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2625
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2626
    self error:'unimplemented operation'.
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2627
    ^ self
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2628
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2629
    "Modified: 1.3.1997 / 17:25:50 / cg"
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2630
!
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2631
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2632
paintBasis
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2633
    "huh - whats that;
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2634
     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
  2635
     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
  2636
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2637
    ^ ColorValue
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2638
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2639
    "Created: 6.3.1997 / 15:24:19 / cg"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2640
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2641
1325
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2642
preferredBounds
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2643
    ^ self bounds
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2644
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2645
    "Created: 10.2.1997 / 12:42:36 / cg"
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2646
!
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2647
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2648
tile:bounds from:origin in:tile rule:rule
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2649
    |orgX orgY tW tH|
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2650
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2651
    origin ~= (0@0) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2652
        self shouldImplement.
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2653
    ].
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2654
    bounds ~= self bounds ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2655
        self shouldImplement.
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2656
    ].
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2657
    rule ~= #over ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2658
        self shouldImplement.
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2659
    ].
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2660
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2661
    orgX := origin x.
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2662
    orgY := origin y.
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2663
    tW := tile width.
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2664
    tH := tile height.
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2665
    (bounds top) to:(bounds bottom) by:tH do:[:dstY |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2666
        (bounds left) to:(bounds right) by:(tile width) do:[:dstX |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2667
            self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2668
                copyFrom:tile
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2669
                x:orgX y:orgY
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2670
                toX:dstX y:dstY
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2671
                width:tW height:tH.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2672
        ].
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2673
    ].
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2674
!
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2675
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2676
valueAtPoint:aPoint put:aColorValue
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2677
    aColorValue isInteger ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2678
        self colorAtX:aPoint x y:aPoint y put:aColorValue
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2679
    ] ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2680
        self pixelAtX:aPoint x y:aPoint y put:aColorValue
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2681
    ]
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2682
! !
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2683
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2684
!Image methodsFor:'accessing'!
48194c26a46c Initial revision
claus
parents:
diff changeset
  2685
6912
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2686
bitsARGB32
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2687
    | bitsARGB32 |
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2688
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2689
    bitsARGB32 := ByteArray new: width * height * 4.
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2690
    self bitsARGB32Into: bitsARGB32.
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2691
    ^ bitsARGB32
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2692
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2693
    "Created: / 01-09-2015 / 18:02:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2694
!
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2695
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2696
bitsARGB32Into: buffer
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2697
    self bitsARGB32Into: buffer startingAt: 1
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2698
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2699
    "Created: / 01-09-2015 / 17:18:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2700
!
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2701
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2702
bitsARGB32Into: buffer startingAt: first
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2703
    self bitsARGB32Into: buffer startingAt: first stride: width
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2704
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2705
    "Created: / 01-09-2015 / 17:18:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2706
!
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2707
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2708
bitsARGB32Into: buffer startingAt: first stride: stride
7170
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2709
    "Store each pixel is a 32-bit quantity, with alpha in the upper 
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2710
     8 bits, then red, then green, then blue. The 32-bit quantities are 
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2711
     stored native-endian. Pre-multiplied alpha is used. (That is, 50% 
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2712
     transparent red is 0x80800000, not 0x80ff0000.)"
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2713
6912
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2714
    mask isNil ifTrue:[ 
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2715
        0 to: height - 1 do:[:y |  
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2716
            | base |
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2717
            base := (first - 1) + (y * stride).
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2718
            0 to: width - 1 do:[:x |  
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2719
                | pixel color offset |
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2720
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2721
                offset := base + (x * 4).    
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2722
                pixel := self pixelAtX: x y: y.
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2723
                color := self colorFromValue: pixel.
7170
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2724
                buffer at: (offset + ARGB_R_OFFSET_MACHINE) put: color redByte.  
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2725
                buffer at: (offset + ARGB_G_OFFSET_MACHINE) put: color greenByte.  
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2726
                buffer at: (offset + ARGB_B_OFFSET_MACHINE) put: color blueByte.  
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2727
                buffer at: (offset + ARGB_A_OFFSET_MACHINE) put: 16rFF.   
6912
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2728
            ]
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2729
        ]
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2730
    ] ifFalse:[ 
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2731
    mask depth == 1 ifTrue:[ 
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2732
        0 to: height - 1 do:[:y |  
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2733
            | base |
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2734
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2735
            base := (first - 1) + (y * stride).
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2736
            0 to: width - 1 do:[:x |  
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2737
                | pixel color offset |
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2738
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2739
                offset := base + (x * 4).
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2740
                (mask pixelAtX: x y:y) ifTrue:[ 
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2741
                    pixel := self pixelAtX: x y: y.
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2742
                    color := self colorFromValue: pixel.
7170
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2743
                    buffer at: (offset + ARGB_R_OFFSET_MACHINE) put: color redByte.  
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2744
                    buffer at: (offset + ARGB_G_OFFSET_MACHINE) put: color greenByte.  
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2745
                    buffer at: (offset + ARGB_B_OFFSET_MACHINE) put: color blueByte.  
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2746
                    buffer at: (offset + ARGB_A_OFFSET_MACHINE) put: 16rFF.
6912
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2747
                ] ifFalse:[ 
7170
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2748
                    buffer at: (offset + ARGB_R_OFFSET_MACHINE) put: 0.  
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2749
                    buffer at: (offset + ARGB_G_OFFSET_MACHINE) put: 0.  
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2750
                    buffer at: (offset + ARGB_B_OFFSET_MACHINE) put: 0.  
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2751
                    buffer at: (offset + ARGB_A_OFFSET_MACHINE) put: 0.
6912
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2752
                ].
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2753
            ]
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2754
        ]
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2755
    ] ifFalse:[ 
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2756
    mask depth == 8 ifTrue:[ 
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2757
        0 to: height - 1 do:[:y |  
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2758
            | base |
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2759
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2760
            base := (first - 1) + (y * stride).
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2761
            0 to: width - 1 do:[:x |  
7170
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2762
                | pixel color offset alpha |
6912
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2763
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2764
                offset := base + (x * 4).
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2765
                pixel := self pixelAtX: x y: y.
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2766
                color := self colorFromValue: pixel.
7170
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2767
                alpha := mask pixelAtX: x y:y.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2768
                buffer at: (offset + ARGB_R_OFFSET_MACHINE) put: (color redByte * alpha) // 16rFF.  
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2769
                buffer at: (offset + ARGB_G_OFFSET_MACHINE) put: (color greenByte * alpha) // 16rFF.  
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2770
                buffer at: (offset + ARGB_B_OFFSET_MACHINE) put: (color blueByte * alpha) // 16rFF.  
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2771
                buffer at: (offset + ARGB_A_OFFSET_MACHINE) put: alpha
6912
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2772
            ]
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2773
        ]
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2774
    ]]].
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2775
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2776
    "Created: / 01-09-2015 / 17:16:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
7170
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2777
    "Modified: / 28-02-2016 / 14:38:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
6912
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2778
!
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2779
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2780
bitsPerSample
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2781
    "return the number of bits per sample.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2782
     The return value is an array of bits-per-plane."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2783
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2784
    bitsPerSample notNil ifTrue:[^ bitsPerSample].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2785
    ^ Array with:self depth
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2786
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2787
    "Modified: 10.6.1996 / 18:04:21 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2788
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2789
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2790
colorMap
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2791
    "return the colormap"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2792
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2793
    ^ colorMap
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2794
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2795
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2796
colorMap:aColorMap
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2797
    "set the colorMap; this also sets the photometric to a useful default."
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  2798
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  2799
    |oldSize "{ Class: SmallInteger }"
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2800
     sameColors|
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2801
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2802
    (aColorMap isNil and:[colorMap isNil]) ifTrue:[^ self].
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2803
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2804
    sameColors := false.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2805
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2806
    photometric == #palette ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2807
        "/ any change at all ?
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  2808
        oldSize := colorMap size.
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  2809
        aColorMap size >= oldSize ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2810
            sameColors := true.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2811
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2812
            1 to:oldSize do:[:idx |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2813
                (aColorMap at:idx) = (colorMap at:idx) ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2814
                    sameColors := false.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2815
                ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2816
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2817
        ].
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2818
    ].
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2819
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2820
    self setColorMap:aColorMap.
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2821
    sameColors ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2822
        ^ self
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2823
    ].
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2824
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  2825
    colorMap notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2826
        photometric := #palette.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  2827
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2828
        (photometric == #palette) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2829
            photometric := #blackIs0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2830
        ]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  2831
    ].
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2832
    deviceForm notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2833
        self release
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2834
    ]
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2835
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  2836
    "Modified: / 31-08-1995 / 03:05:59 / claus"
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  2837
    "Modified: / 22-08-1998 / 12:29:58 / cg"
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  2838
    "Modified: / 31-01-2017 / 14:48:56 / stefan"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2839
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2840
2068
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
  2841
colorMapFromArray: anArray
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2842
    "set the colorMap by reading colors from an array with rgb-byte values.
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2843
     The (byte-)Array argument should be of the form:
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2844
        #( red0 green0 blue0  red1 green1 blue1 ... redN greenN blueN)
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2845
     where each component must be a byteValue in 0..255."
2068
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
  2846
3876
f4dc6267a30a getting rid of colorMap
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  2847
    self colorMap:(MappedPalette rgbBytesVector:anArray)
3864
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
  2848
!
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
  2849
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
  2850
colorMapFromRGBValueArray:anArray
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2851
    "set the colorMap by reading colors from an array with rgb-integer values.
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2852
     The (integer-)Array argument should be of the form:
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2853
        #( rgb0 rgb1  ... rgbN)
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2854
     where each element must be an rgbValue in 0..FFFFFF."
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2855
3876
f4dc6267a30a getting rid of colorMap
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  2856
    self colorMap:(MappedPalette rgbValueVector:anArray)
2068
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
  2857
!
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
  2858
757
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2859
container:aVisualContainer
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2860
    "ignored here - added to allow images to be used like
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2861
     VisualComponents (later, Image should inherit from it)"
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2862
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2863
    "Created: 28.5.1996 / 23:43:49 / cg"
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2864
    "Modified: 29.5.1996 / 10:22:23 / cg"
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2865
!
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2866
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2867
depth
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2868
    "return the depth of the image"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2869
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2870
    ^ self bitsPerPixel
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2871
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2872
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2873
device
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2874
    "return the device, the receiver is associated with.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2875
     Return nil, if the image is unassigned."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2876
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2877
    ^ device
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2878
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2879
7637
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  2880
drawableId
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  2881
    "return the id of the image on the device.
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  2882
     Return nil, if the image is unassigned."
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  2883
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  2884
    deviceForm isNil ifTrue:[^ nil].
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  2885
    ^ deviceForm drawableId
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  2886
!
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  2887
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2888
extent
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2889
    "return the images extent"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2890
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2891
    ^ width@height
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2892
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2893
1950
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2894
fileName
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2895
    "return the value of the instance variable 'fileName' (automatically generated)"
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2896
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2897
    ^ fileName
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2898
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2899
    "Created: / 3.11.1997 / 14:54:46 / cg"
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2900
!
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2901
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2902
fileName:something
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2903
    "set the value of the instance variable 'fileName' (automatically generated)"
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2904
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2905
    fileName := something.
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2906
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2907
    "Created: / 3.11.1997 / 14:54:46 / cg"
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2908
!
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2909
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2910
fullColorId
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2911
    "return the id of the full color image on the device.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2912
     Return nil, if the image is unassigned."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2913
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2914
    fullColorDeviceForm isNil ifTrue:[^ nil].
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2915
    ^ fullColorDeviceForm id
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2916
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2917
728
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  2918
graphicsDevice
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  2919
    "same as #device - for ST-80 compatibility"
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  2920
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  2921
    ^ device
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  2922
!
744
db883c9b74b8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 728
diff changeset
  2923
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2924
height
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2925
    "return the height of the image"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2926
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2927
    ^ height
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2928
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2929
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2930
id
7637
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  2931
    ^ self drawableId  
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2932
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2933
2081
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2934
imageSequence
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2935
    "return the frameSequence of which this image is a part of;
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2936
     nil if it is not part of a sequence."
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2937
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2938
    ^ imageSequence
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2939
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2940
    "Created: / 1.4.1998 / 14:43:00 / cg"
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2941
!
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2942
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2943
imageSequence:aCollection
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2944
    "private entry for imageReaders - set the frameSequence of which
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2945
     this image is a part of"
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2946
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2947
    imageSequence := aCollection
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2948
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2949
    "Created: / 1.4.1998 / 14:42:36 / cg"
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2950
!
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2951
896
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2952
mask
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2953
    ^ mask
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2954
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2955
    "Created: 21.6.1996 / 12:57:44 / cg"
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2956
!
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2957
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2958
mask:anotherImage
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2959
    "set the images mask - currently, this may be nil or a Depth1Image.
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2960
     (it is planned to support alpha information in a Depth8 maskImage in
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2961
      the near future).
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2962
     For depth1 masks: each pixel of the image where a corresponding
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2963
                       1-bit is present in the mask will be drawn;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2964
                       0-bit mask pixels lead to transparent pixels.
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2965
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2966
     For depth8 masks: (future):
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2967
                       each pixel specifies the alpha value (0..255),
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2968
                       which specifies the transparency of that pixel.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2969
                       0 means completely transparent, 255 means completely
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2970
                       opaque. The 1-plane mask is a special case of this,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2971
                       interpreting a 0 as a 0 alpha value and 1's as an
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2972
                       alpha value of 255."
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2973
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2974
    mask := anotherImage.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2975
    maskedPixelsAre0 := false.
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2976
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2977
    "Created: 27.6.1996 / 17:45:22 / cg"
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2978
    "Modified: 12.4.1997 / 12:04:39 / cg"
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2979
!
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2980
1587
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2981
maskedPixelsAre0
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2982
    "return true if masked pixels have been cleared to zero"
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2983
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2984
    ^ maskedPixelsAre0 == true
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2985
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2986
    "Modified: / 22.8.1998 / 11:27:22 / cg"
1587
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2987
!
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2988
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2989
maskedPixelsAre0:aBoolean
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2990
    "set/clear the flag which states if masked pixels
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2991
     have been set to zero. Knowing this to be true allows
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2992
     faster drawing of the image later; (however, not setting
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2993
     it will still produce correct output).
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2994
     This flag is typically set by image readers."
1587
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2995
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2996
    maskedPixelsAre0 := aBoolean
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2997
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2998
    "Modified: 12.4.1997 / 12:08:42 / cg"
1587
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2999
!
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  3000
7374
b1a4e6ba38cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7373
diff changeset
  3001
metaData
b1a4e6ba38cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7373
diff changeset
  3002
    ^ metaData
b1a4e6ba38cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7373
diff changeset
  3003
!
b1a4e6ba38cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7373
diff changeset
  3004
b1a4e6ba38cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7373
diff changeset
  3005
metaData:something
b1a4e6ba38cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7373
diff changeset
  3006
    metaData := something.
b1a4e6ba38cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7373
diff changeset
  3007
!
b1a4e6ba38cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7373
diff changeset
  3008
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3009
monochromeId
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3010
    "return the id of the monochrome image on the device.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3011
     Return nil, if the image is unassigned."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3012
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3013
    monoDeviceForm isNil ifTrue:[^ nil].
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3014
    ^ monoDeviceForm id
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3015
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3016
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3017
palette
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3018
    "return the colormap; ST-80 compatibility"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3019
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3020
    ^ colorMap
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3021
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3022
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3023
palette:aColormap
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3024
    "set the colormap; ST-80 compatibility"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3025
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  3026
    self colorMap:aColormap
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3027
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3028
    "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
  3029
    "Modified: 8.6.1996 / 09:54:02 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3030
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3031
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3032
photometric
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  3033
    "return the photometric, a symbol such as #palette, #rgb etc.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  3034
     This may be a somewhat old leftover from times, when tiff was the first image file type to be read.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  3035
     Much better would be to always have some (possibly fake and virtual) colormap around, and ask that one.
7373
61933c223183 added metaData instVar (for free use by image reader)
Claus Gittinger <cg@exept.de>
parents: 7363
diff changeset
  3036
     However, in the meantime, many other classes depend on that, so that it should be kept as an API
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  3037
     - even when the internal representation will be replaced by something better in the future."
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  3038
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3039
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3040
    ^ photometric
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3041
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3042
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3043
samplesPerPixel
6840
3dee5e952e94 class: Image
Stefan Vogel <sv@exept.de>
parents: 6831
diff changeset
  3044
    "return the number of samples per pixel in the image."
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3045
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3046
    samplesPerPixel notNil ifTrue:[^ samplesPerPixel].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3047
    ^ 1
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3048
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3049
    "Modified: 10.6.1996 / 18:03:30 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3050
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3051
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  3052
setColorMap:aColorMap
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  3053
    colorMap isColormap ifTrue:[
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  3054
        colorMap := aColorMap.
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  3055
    ] ifFalse:[
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  3056
        colorMap := MappedPalette withColors:aColorMap.
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  3057
    ].
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  3058
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  3059
    "Modified: / 30-01-2017 / 19:15:34 / stefan"
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  3060
!
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  3061
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3062
width
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3063
    "return the width of the image"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3064
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3065
    ^ width
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3066
! !
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3067
3263
bd92a12c9316 category changes
Claus Gittinger <cg@exept.de>
parents: 3259
diff changeset
  3068
!Image methodsFor:'accessing-pixels'!
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3069
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3070
at:aPoint
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3071
    "WARNING: for now, this returns a pixels color
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3072
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3073
     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
  3074
     Use #colorAt: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3075
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3076
     retrieve the pixel at aPoint; return a color.
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3077
     Pixels start at 0@0 for upper left pixel, end at
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3078
     (width-1)@(height-1) for lower right pixel.
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3079
     You should not use this method for image-processing, its
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3080
     very slow ...
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3081
     (it is meant to access individual pixels - for example, in a bitmap editor)"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3082
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  3083
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  3084
7482
0e29bd25788b #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 7481
diff changeset
  3085
    self obsoleteFeatureWarning:'Image [warning]: the Image>>at: will change semantics soon; use #colorAt:'.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3086
    ^ self colorAtX:(aPoint x) y:(aPoint y)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3087
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
  3088
    "Modified: / 21.6.1997 / 13:10:17 / cg"
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
  3089
    "Modified: / 9.1.1998 / 20:33:52 / stefan"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3090
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  3091
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3092
at:aPoint put:aColor
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3093
    "WARNING: for now, this expects a pixels color
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3094
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3095
     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
  3096
     Use #colorAt:put: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3097
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3098
     set the pixel at aPoint to aColor.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3099
     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
  3100
     (width-1)@(height-1) for lower right pixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3101
     You should not use this method for image-processing, its
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3102
     very slow ...
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3103
     (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
  3104
7482
0e29bd25788b #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 7481
diff changeset
  3105
    aColor isInteger ifTrue:[
0e29bd25788b #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 7481
diff changeset
  3106
        ^ self pixelAtX:aPoint x y:aPoint y put:aColor.
0e29bd25788b #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 7481
diff changeset
  3107
    ].
0e29bd25788b #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 7481
diff changeset
  3108
    self obsoleteFeatureWarning:'Image [warning]: the Image>>at:put: will change semantics soon; use #colorAt:put:'.
0e29bd25788b #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 7481
diff changeset
  3109
    ^ self colorAtX:aPoint x y:aPoint y put:aColor.
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  3110
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
  3111
    "Modified: / 21.6.1997 / 13:16:02 / cg"
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
  3112
    "Modified: / 9.1.1998 / 20:34:15 / stefan"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3113
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3114
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3115
atImageAndMask:aPoint put:aColorOrPixelOrNil
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  3116
    "set the pixel at x/y to aColor.
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3117
     If aColor is a mask color (i.e. Color noColor) the mask pixel will be set to 0 (transparent),
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3118
     otherwise to 1. Nil is treated like noColor.
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  3119
     (used by the bitmap editor)"
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  3120
2523
4c197af8cc50 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2502
diff changeset
  3121
    |maskVal|
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3122
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3123
    (aColorOrPixelOrNil notNil and:[aColorOrPixelOrNil ~= Color noColor]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3124
        maskVal := 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3125
        aColorOrPixelOrNil isInteger ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3126
            self pixelAt:aPoint put:aColorOrPixelOrNil.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3127
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3128
            self colorAt:aPoint put:aColorOrPixelOrNil
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3129
        ]
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3130
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3131
        maskVal := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3132
        self pixelAt:aPoint put:0.
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3133
    ].
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3134
    mask notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3135
        mask pixelAt:aPoint put:maskVal
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3136
    ].
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3137
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3138
    "Modified: / 30.9.1998 / 22:42:44 / cg"
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3139
!
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3140
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3141
atImageAndMask:aPoint putValue:aPixelValueOrNil
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3142
    "set the pixel at x/y to aColor.
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3143
     If aPixelValueOrNil is nil, the mask pixel will be set to 0 (transparent),
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  3144
     otherwise to 1. (used by the bitmap editor)"
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3145
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3146
    |pixVal maskVal|
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3147
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3148
    aPixelValueOrNil notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3149
        pixVal := aPixelValueOrNil.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3150
        maskVal := 1.
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3151
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3152
        pixVal := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3153
        maskVal := 0.
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3154
    ].
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3155
    mask notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3156
        mask pixelAt:aPoint put:maskVal
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3157
    ].
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3158
    self pixelAt:aPoint put:pixVal
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3159
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3160
    "Modified: / 30.9.1998 / 22:42:44 / cg"
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  3161
!
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  3162
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3163
atPoint:aPoint
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3164
    "ST-80 compatibility: return the pixelValue at:aPoint."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3165
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3166
    ^ self pixelAtX:aPoint x y:aPoint y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3167
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3168
    "Modified: 24.4.1997 / 16:18:44 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3169
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3170
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3171
atPoint:aPoint put:aPixelValue
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3172
    "ST-80 compatibility: set the pixelValue at:aPoint."
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3173
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3174
    ^ self pixelAtX:aPoint x y:aPoint y put:aPixelValue
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3175
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3176
    "Modified: 24.4.1997 / 17:17:59 / cg"
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3177
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3178
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3179
atX:x y:y
7482
0e29bd25788b #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 7481
diff changeset
  3180
    <resource: #obsolete>
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3181
    "WARNING: for now, this returns a pixels color
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3182
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3183
     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
  3184
     Use #colorAt: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3185
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3186
     Retrieve a pixel at x/y; return a color.
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3187
     Pixels start at 0@0 for upper left pixel, end at
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3188
     (width-1)@(height-1) for lower right pixel.
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3189
     You should not use this method for image-processing, its
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3190
     very slow ...
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3191
     (it is meant to access individual pixels - for example, in a bitmap editor)"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3192
7482
0e29bd25788b #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 7481
diff changeset
  3193
    self obsoleteFeatureWarning:'Image [warning]: the Image>>atX:y: will change semantics soon; use #colorAtX:y:'.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3194
    ^ self colorAtX:x y:y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3195
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  3196
    "Modified: 21.6.1997 / 13:10:32 / cg"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3197
!
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3198
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3199
atX:x y:y put:aColor
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3200
    "WARNING: for now, this expects a pixels color
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3201
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3202
     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
  3203
     Use #colorAt:put: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3204
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3205
     set the pixel at x/y to aColor.
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3206
     Pixels start at 0@0 for the upper left pixel, end at
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3207
     (width-1)@(height-1) for the lower right pixel.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  3208
     This method checks if the color can be stored in the image.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  3209
     (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
  3210
     You should not use this method for image-processing, it is very slow ...
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3211
     (it is meant to access individual pixels - for example, in a bitmap editor)"
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3212
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  3213
    aColor isInteger ifTrue:[
7482
0e29bd25788b #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 7481
diff changeset
  3214
        ^ self pixelAtX:x y:y put:aColor
0e29bd25788b #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 7481
diff changeset
  3215
    ].
0e29bd25788b #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 7481
diff changeset
  3216
    self obsoleteFeatureWarning:'Image [warning]: the Image>>atX:y:put: will change semantics soon; use #colorAtX:y:put:'.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3217
    ^ self colorAtX:x y:y put:aColor
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3218
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  3219
    "Modified: 21.6.1997 / 13:10:44 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3220
!
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3221
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3222
atX:x y:y putValue:aPixelValue
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3223
    "set the pixel at x/y to aPixelValue.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3224
     The interpretation of the pixelValue depends on the photometric
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3225
     and the colormap. (see also: Image>>atX:y:put:)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3226
     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
  3227
     (width-1) @ (height-1) for the lower right pixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3228
     You should not use this method for image-processing, its
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3229
     very slow ...
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3230
     (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
  3231
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  3232
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  3233
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3234
    self obsoleteMethodWarning:'use #pixelAtX:y:put:'.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3235
    ^ self pixelAtX:x y:y put:aPixelValue.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3236
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3237
    "Modified: 24.4.1997 / 17:15:45 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3238
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3239
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3240
bits
7373
61933c223183 added metaData instVar (for free use by image reader)
Claus Gittinger <cg@exept.de>
parents: 7363
diff changeset
  3241
    "return the raw image data (pixel data);
61933c223183 added metaData instVar (for free use by image reader)
Claus Gittinger <cg@exept.de>
parents: 7363
diff changeset
  3242
     depending on the photometric, this has to be interpreted as monochrome,
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3243
     greyscale, palette or rgb data.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3244
     It is also packed to be dense, so a 4 bitPerSample palette image
4415
be0fa075e4c4 comment
Claus Gittinger <cg@exept.de>
parents: 4414
diff changeset
  3245
     will store 2 pixels per byte, whereas a 2-bitPerPixel image will store
be0fa075e4c4 comment
Claus Gittinger <cg@exept.de>
parents: 4414
diff changeset
  3246
     4 pixels per byte."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3247
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3248
    bytes isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3249
        pixelFunction notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3250
            self createPixelStore.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3251
            0 to:height-1 do:[:y |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3252
                0 to:width-1 do:[:x |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3253
                    self pixelAtX:x y:y put:(pixelFunction value:x value:y)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3254
                ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3255
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3256
        ].
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3257
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3258
    ^ bytes
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3259
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3260
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3261
colAt:x into:aPixelBuffer
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3262
    "fill aBuffer with pixel values retrieved from a single column.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3263
     (eg. a vertical span)    
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3264
     Notice: row/column coordinates start at 0."
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3265
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3266
    ^ self colAt:x into:aPixelBuffer startingAt:1
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3267
!
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3268
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3269
colAt:x into:aPixelBuffer startingAt:startIndex
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3270
    "fill aBuffer with pixel values retrieved from a single column.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3271
     (eg. a vertical span)    
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3272
     Notice: row/column coordinates start at 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3273
     This is a slow fallBack method, which works with any depth;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3274
     concrete image subclasses should redefine this for more performance."
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3275
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3276
    |h "{ Class: SmallInteger }"|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3277
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3278
    h := height-1.    
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3279
    0 to:h do:[:row |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3280
        aPixelBuffer at:(row + startIndex) put:(self pixelAtX:x y:row)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3281
    ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3282
!
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3283
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3284
colAt:x putAll:pixelArray
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3285
    "store a single column's pixels from bits in the argument;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3286
     (eg. a vertical span)    
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3287
     Notice: row/column coordinates start at 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3288
     This is a slow fallBack method, which works with any depth;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3289
     concrete image subclasses should redefine this for more performance."
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3290
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3291
    ^ self colAt:x putAll:pixelArray startingAt:1
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3292
!
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3293
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3294
colAt:x putAll:pixelArray startingAt:startIndex
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3295
    "store a single row's pixels from bits in the pixelArray argument.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3296
     (eg. a vertical span)    
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3297
     Notice: row/column coordinates start at 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3298
     This is a slow fallBack method, which works with any depth;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3299
     concrete image subclasses should redefine this for more performance."
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3300
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3301
    |h "{ Class: SmallInteger }"|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3302
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3303
    h := height-1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3304
    0 to:h do:[:row |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3305
        self pixelAtX:x y:row put:(pixelArray at:(row + startIndex))
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3306
    ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3307
    ^ pixelArray
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3308
!
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3309
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3310
colorAt:aPoint
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3311
    "retrieve a pixel at x/y; return a color.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3312
     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
  3313
     (width-1)@(height-1) for lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3314
     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
  3315
     very slow ...
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3316
     (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
  3317
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3318
    ^ self colorAtX:(aPoint x) y:(aPoint y)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3319
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3320
    "Created: 24.4.1997 / 17:02:31 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3321
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3322
1962
8c7377d243f6 save mask in storeOn.
tz
parents: 1950
diff changeset
  3323
colorAt: aPoint put:aColor
8c7377d243f6 save mask in storeOn.
tz
parents: 1950
diff changeset
  3324
8c7377d243f6 save mask in storeOn.
tz
parents: 1950
diff changeset
  3325
    self colorAtX: aPoint x y: aPoint y put:aColor
8c7377d243f6 save mask in storeOn.
tz
parents: 1950
diff changeset
  3326
!
8c7377d243f6 save mask in storeOn.
tz
parents: 1950
diff changeset
  3327
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3328
colorAtX:x y:y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3329
    "retrieve a pixel at x/y; return a color.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3330
     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
  3331
     (width-1)@(height-1) for lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3332
     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
  3333
     very slow ...
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3334
     (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
  3335
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3336
    |pixel|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3337
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3338
    pixel := self pixelAtX:x y:y.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3339
    ^ self colorFromValue:pixel
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3340
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3341
    "Modified: 24.4.1997 / 16:18:53 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3342
    "Created: 24.4.1997 / 17:00:52 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3343
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3344
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3345
colorAtX:x y:y put:aColor
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3346
    "set the pixel at x/y to aColor.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3347
     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
  3348
     (width-1)@(height-1) for the lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3349
     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
  3350
     (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
  3351
     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
  3352
     (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
  3353
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3354
    |pixel|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3355
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3356
    pixel := self valueFromColor:aColor.
2182
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3357
    pixel isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3358
        ^ UnrepresentableColorSignal raiseErrorString:'cannot store color - not in colormap'.
2182
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3359
    ].
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3360
    self pixelAtX:x y:y put:pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3361
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3362
    "Modified: 24.4.1997 / 17:36:20 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3363
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3364
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3365
data
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3366
    "for backward compatibility - will vanish"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3367
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  3368
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  3369
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3370
    self obsoleteMethodWarning:'use #bits'.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3371
    ^ self bits
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3372
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3373
    "Modified: 24.4.1997 / 17:37:57 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3374
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3375
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3376
data:aByteArray
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3377
    "for backward compatibility - will vanish"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3378
4175
a9e65365e590 Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 4173
diff changeset
  3379
    <resource:#obsolete>
3966
950a2db201c7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3964
diff changeset
  3380
    self obsoleteMethodWarning:'use #bits:'.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3381
    self bits:aByteArray
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3382
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3383
    "Modified: 24.4.1997 / 17:38:18 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3384
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3385
2182
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3386
maskAt:aPoint
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3387
    "retrieve the maskValue at aPoint - an integer number which is
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3388
     0 for masked pixels (invisible), 1 for unmasked (visible).
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3389
     For images without mask, 1 is returned for all pixels."
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3390
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3391
    ^ self maskAtX:aPoint x y:aPoint y
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3392
!
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3393
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3394
maskAt:aPoint put:maskValue
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3395
    "set the maskValue at aPoint - an integer number which is
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3396
     0 for masked pixels (invisible), 1 for unmasked (visible)."
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3397
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3398
    ^ self maskAtX:aPoint x y:aPoint y put:maskValue
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3399
!
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3400
2182
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3401
maskAtX:x y:y
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3402
    "retrieve the maskValue at aPoint - an integer number which is
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3403
     0 for masked pixels (invisible), 1 for unmasked (visible).
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3404
     For images without mask, 1 is returned for all pixels."
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3405
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3406
    mask isNil ifTrue:[^ 1].
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3407
    ^ mask pixelAtX:x y:y
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3408
!
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3409
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3410
maskAtX:x y:y put:maskValue
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3411
    "set the maskValue at aPoint - an integer number which is
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3412
     0 for masked pixels (invisible), 1 for unmasked (visible)."
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3413
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3414
    mask isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3415
        maskValue == 1 ifTrue:[^ self].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3416
        self error:'image has no mask'.
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3417
    ].
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3418
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3419
    ^ mask pixelAtX:x y:y put:maskValue
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3420
!
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3421
2205
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3422
pixelAt:aPoint
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3423
    "retrieve a pixel at x/y; return a pixel value.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3424
     Pixels start at 0@0 for upper left pixel, end at
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3425
     (width-1)@(height-1) for lower right pixel.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3426
     You should not use this method for image-processing, its
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3427
     very slow ...
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3428
     (it is meant to access individual pixels - for example, in a bitmap editor)"
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3429
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3430
    ^ self pixelAtX:(aPoint x) y:(aPoint y)
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3431
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3432
    "Created: / 29.7.1998 / 02:48:52 / cg"
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3433
!
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3434
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3435
pixelAt:aPoint put:aPixelValue
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3436
    "set the pixel at x/y to aPixelValue.
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3437
     The interpretation of the pixelValue depends on the photometric
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3438
     and the colormap. (see also: Image>>atX:y:put:)
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3439
     Pixels start at 0@0 for the upper left pixel, end at
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3440
     (width-1) @ (height-1) for the lower right pixel.
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3441
     You should not use this method for image-processing, its
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3442
     very slow ...
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3443
     (it is meant to access individual pixels - for example, in a bitmap editor)"
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3444
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3445
    ^ self pixelAtX:aPoint x y:aPoint y put:aPixelValue
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3446
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3447
    "Created: / 30.9.1998 / 22:40:43 / cg"
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3448
!
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3449
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3450
pixelAtX:x y:y
7519
c0603c8183dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7511
diff changeset
  3451
    "retrieve the pixelValue at aPoint; return a pixel (an integer number).
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3452
     Pixels start at 0/0 for upper left pixel, and end at
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3453
     width-1@height-1 for lower right pixel.
7519
c0603c8183dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7511
diff changeset
  3454
     The returned number's interpretation depends on the photometric
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3455
     and the colormap. (see also Image>>at: and Image>>atX:y:)
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3456
     You should not use this method for image-processing of
7519
c0603c8183dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7511
diff changeset
  3457
     big images, it's very slow ...
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3458
     (it is meant to access individual pixels - for example, in a bitmap editor)"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3459
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3460
    pixelFunction notNil ifTrue:[^ pixelFunction value:x value:y].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3461
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3462
    ^ self subclassResponsibility
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3463
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3464
    "Created: 24.4.1997 / 16:06:56 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3465
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3466
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3467
pixelAtX:x y:y put:aPixelValue
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3468
    "set the pixel at x/y to aPixelValue.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3469
     The interpretation of the pixelValue depends on the photometric
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3470
     and the colormap. (see also: Image>>atX:y:put:)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3471
     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
  3472
     (width-1) @ (height-1) for the lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3473
     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
  3474
     very slow ...
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3475
     (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
  3476
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3477
    ^ self subclassResponsibility
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3478
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3479
    "Created: 24.4.1997 / 17:05:11 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3480
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3481
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3482
rgbValueAt:aPoint
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3483
    "retrieve a pixels rgb value at x/y; return a 24bit rgbValue (rrggbb, red is MSB).
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3484
     Pixels start at 0@0 for upper left pixel, end at (width-1)@(height-1) for lower right pixel."
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3485
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3486
    ^ self rgbValueAtX:(aPoint x) y:(aPoint y)
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3487
!
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3488
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3489
rgbValueAtX:x y:y
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3490
    "retrieve a pixels rgb value at x/y; return a 24bit rgbValue (rrggbb, red is MSB).
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3491
     Pixels start at 0@0 for upper left pixel, end at (width-1)@(height-1) for lower right pixel."
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3492
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3493
    |pixel|
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3494
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3495
    pixel := self pixelAtX:x y:y.
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3496
    ^ self rgbFromValue:pixel
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3497
!
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3498
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  3499
rgbValueAtX:x y:y put:newRGBValue
4858
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3500
    |value|
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3501
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3502
    value := self valueFromRGB:newRGBValue.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3503
    self pixelAtX:x y:y put:value.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3504
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3505
    "Created: / 15-01-2008 / 15:56:10 / cg"
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3506
!
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3507
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3508
rowAt:y
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3509
    "retrieve an array filled with pixel values from a single row.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3510
     (eg. a horizontal span)    
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3511
     Notice: row/column coordinates start at 0.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3512
     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
  3513
     concrete image subclasses should redefine this for more performance."
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3514
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3515
    |pixelArray|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3516
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3517
    pixelArray := self pixelArraySpecies new:width.
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3518
    self rowAt:y into:pixelArray startingAt:1.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3519
    ^ pixelArray
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3520
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3521
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3522
     |i|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3523
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3524
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3525
     (i rowAt:0) inspect
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3526
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3527
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3528
     |i|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3529
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  3530
     i := Image fromFile:'libtool/bitmaps/SBrowser.xbm'.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3531
     (i rowAt:0) inspect
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3532
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3533
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3534
    "Modified: 24.4.1997 / 15:51:24 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3535
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3536
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3537
rowAt:y into:aPixelBuffer
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3538
    "fill aBuffer with pixel values retrieved from a single row.
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3539
     (eg. a horizontal span)    
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3540
     Notice: row/column coordinates start at 0."
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3541
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3542
    ^ self rowAt:y into:aPixelBuffer startingAt:1
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3543
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3544
    "Created: 24.4.1997 / 15:44:46 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3545
    "Modified: 24.4.1997 / 15:51:35 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3546
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3547
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3548
rowAt:y into:aPixelBuffer startingAt:startIndex
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3549
    "fill aBuffer with pixel values retrieved from a single row.
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3550
     (eg. a horizontal span)    
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3551
     Notice: row/column coordinates start at 0.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3552
     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
  3553
     concrete image subclasses should redefine this for more performance."
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3554
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3555
    |w "{ Class: SmallInteger }"|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3556
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3557
    w := width-1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3558
    0 to:w do:[:col |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3559
        aPixelBuffer at:(col + startIndex) put:(self pixelAtX:col y:y)
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3560
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3561
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3562
    "Created: 24.4.1997 / 15:05:21 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3563
    "Modified: 24.4.1997 / 16:52:43 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3564
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3565
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3566
rowAt:y putAll:pixelArray
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3567
    "store a single row's pixels from bits in the argument;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3568
     (eg. a horizontal span)    
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3569
     Notice: row/column coordinates start at 0.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3570
     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
  3571
     concrete image subclasses should redefine this for more performance."
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3572
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3573
    ^ self rowAt:y putAll:pixelArray startingAt:1
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3574
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3575
    "Modified: 24.4.1997 / 15:51:58 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3576
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3577
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3578
rowAt:y putAll:pixelArray startingAt:startIndex
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3579
    "store a single row's pixels from bits in the pixelArray argument;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3580
     (eg. a horizontal span)    
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3581
     Notice: row/column coordinates start at 0.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3582
     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
  3583
     concrete image subclasses should redefine this for more performance."
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3584
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3585
    |w "{ Class: SmallInteger }"|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3586
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3587
    w := width-1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3588
    0 to:w do:[:col |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3589
        self pixelAtX:col y:y put:(pixelArray at:(col + startIndex))
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3590
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3591
    ^ pixelArray
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3592
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3593
    "Modified: 24.4.1997 / 17:05:57 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3594
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3595
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3596
valueAt:aPoint
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3597
    "WARNING: for now, this returns a pixels value
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3598
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3599
     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
  3600
     Use #pixelAt: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3601
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3602
     Retrieve the pixelValue at aPoint; return an integer number.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3603
     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
  3604
     width-1@height-1 for lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3605
     The returned numbers interpretation depends on the photometric
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3606
     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
  3607
     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
  3608
     very slow ...
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3609
     (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
  3610
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  3611
    'Image [warning]: the Image>>valueAt: will change semantics soon; use #pixelAt:' infoPrintCR.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3612
    ^ self pixelAtX:aPoint x y:aPoint y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3613
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  3614
    "Modified: 21.6.1997 / 13:11:19 / cg"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3615
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3616
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3617
valueAtX:x y:y
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3618
    "WARNING: for now, this returns a pixels value
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3619
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3620
     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
  3621
     Use #pixelAt: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3622
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3623
     Retrieve the pixelValue at aPoint; return an integer number.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3624
     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
  3625
     width-1@height-1 for lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3626
     The returned numbers interpretation depends on the photometric
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3627
     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
  3628
     You should not use this method for image-processing of
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3629
     big images, its very slow ...
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3630
     (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
  3631
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  3632
    'Image [warning]: the Image>>valueAtX:y: will change semantics soon; use #pixelAtX:y' infoPrintCR.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3633
    ^ self pixelAtX:x y:y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3634
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  3635
    "Modified: 21.6.1997 / 13:11:29 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3636
! !
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3637
3263
bd92a12c9316 category changes
Claus Gittinger <cg@exept.de>
parents: 3259
diff changeset
  3638
!Image methodsFor:'accessing-private'!
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3639
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3640
bits:aByteArray
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3641
    "set the raw data.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3642
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3643
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3644
     instances or by image readers. Calling for a change of an
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3645
     existing image may confuse later pixel interpretation
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3646
     (it does not care for colormaps and/or cached device image flushing)."
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3647
6894
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3648
    |expectedSize d|
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3649
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3650
    bytes := aByteArray.
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3651
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3652
    "/ sanity check:
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3653
    "/ there seem to be images in some image-resource methods,
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3654
    "/ which were written with an invalid packed pixel string.
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3655
    "/ leave this in for a while and watch out for the halt below.
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3656
    "/ If you encounter this halt,
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3657
    "/ please edit the image in the image editor and save it back.
7373
61933c223183 added metaData instVar (for free use by image reader)
Claus Gittinger <cg@exept.de>
parents: 7363
diff changeset
  3658
6894
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3659
    (width notNil and:[height notNil and:[(d := self depth) notNil]]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3660
        (d <= 8) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3661
            expectedSize := (self bytesPerRow * height).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3662
            bytes size < expectedSize ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3663
                Smalltalk isSmalltalkDevelopmentSystem ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3664
                    self breakPoint:#cg info:'invalid bytearray size'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3665
                ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3666
                bytes := (ByteArray new:expectedSize) replaceFrom:1 with:bytes; yourself.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3667
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3668
        ].
6894
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3669
    ].
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3670
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3671
    "Modified: 23.4.1996 / 11:08:28 / cg"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3672
!
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3673
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3674
bits:aByteArrayArg colorMap:clrMapArg
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3675
    "set the raw data.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3676
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3677
     This interface is only to be used when initializing
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3678
     instances or by image readers. Calling for a change of an
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3679
     existing image may confuse later pixel interpretation
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3680
     (it does not care for colormaps and/or cached device image flushing)."
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3681
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3682
    self bits:aByteArrayArg.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3683
    self colorMap:clrMapArg.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3684
!
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3685
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3686
bits:aByteArrayArg colorMap:clrMapArg mask:maskArg
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3687
    "set the raw data.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3688
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3689
     This interface is only to be used when initializing
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3690
     instances or by image readers. Calling for a change of an
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3691
     existing image may confuse later pixel interpretation
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3692
     (it does not care for colormaps and/or cached device image flushing)."
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3693
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3694
    self bits:aByteArrayArg.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3695
    self colorMap:clrMapArg.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3696
    self mask:maskArg
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3697
!
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3698
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3699
bits:aByteArrayArg colorMapFromArray:clrMapArg
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3700
    "set the raw data.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3701
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3702
     This interface is only to be used when initializing
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3703
     instances or by image readers. Calling for a change of an
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3704
     existing image may confuse later pixel interpretation
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3705
     (it does not care for colormaps and/or cached device image flushing)."
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3706
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3707
    self bits:aByteArrayArg.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3708
    self colorMapFromArray:clrMapArg.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3709
!
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3710
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3711
bits:aByteArrayArg colorMapFromArray:clrMapArg mask:maskArg
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3712
    "set the raw data.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3713
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3714
     This interface is only to be used when initializing
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3715
     instances or by image readers. Calling for a change of an
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3716
     existing image may confuse later pixel interpretation
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3717
     (it does not care for colormaps and/or cached device image flushing)."
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3718
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3719
    self bits:aByteArrayArg.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3720
    self colorMapFromArray:clrMapArg.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3721
    self mask:maskArg
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3722
!
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3723
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3724
bits:aByteArrayArg mask:maskArg
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3725
    "set the raw data.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3726
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3727
     This interface is only to be used when initializing
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3728
     instances or by image readers. Calling for a change of an
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3729
     existing image may confuse later pixel interpretation
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3730
     (it does not care for colormaps and/or cached device image flushing)."
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3731
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3732
    self bits:aByteArrayArg.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3733
    self mask:maskArg
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3734
!
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3735
4115
0e783379a6b0 Use ByteArray for bitsPerSample (255 should be enough ;-)
Stefan Vogel <sv@exept.de>
parents: 4109
diff changeset
  3736
bitsPerSample:aCollection
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3737
    "set the number of bits per sample.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3738
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3739
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3740
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3741
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3742
7373
61933c223183 added metaData instVar (for free use by image reader)
Claus Gittinger <cg@exept.de>
parents: 7363
diff changeset
  3743
    "/ the following is a trick to get both shared and immutable instances,
61933c223183 added metaData instVar (for free use by image reader)
Claus Gittinger <cg@exept.de>
parents: 7363
diff changeset
  3744
    "/ at least for the most common cases.
7363
778803c164cd #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7349
diff changeset
  3745
    "/ Prevents writers to do what is described above.
778803c164cd #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7349
diff changeset
  3746
    "/ Do not remove, as you might not understand it!!
7373
61933c223183 added metaData instVar (for free use by image reader)
Claus Gittinger <cg@exept.de>
parents: 7363
diff changeset
  3747
    bitsPerSample :=
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3748
        #(
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3749
            #[ 8 8 8 ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3750
            #[ 4 4 4 ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3751
            #[ 8 ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3752
            #[ 4 ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3753
            #[ 2 ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3754
            #[ 1 ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3755
        ) detect:[:bps | bps sameContentsAs:aCollection] ifNone:[aCollection asByteArray].
7363
778803c164cd #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7349
diff changeset
  3756
6899
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  3757
    samplesPerPixel isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3758
        samplesPerPixel := bitsPerSample size.
6899
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  3759
    ].
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3760
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3761
    "Modified: 23.4.1996 / 11:08:31 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3762
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3763
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3764
depth:d
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3765
    "set the depth of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3766
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3767
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3768
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3769
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3770
1362
454d644f6ff7 set depth & bitsPerPixel for ST-80 compatibility.
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
  3771
    depth := self depth.
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
  3772
    "/ bitsPerPixel := d.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3773
    d == 24 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3774
        samplesPerPixel := 3.
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  3775
        bitsPerSample := #[8 8 8]
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3776
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3777
        d == 32 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3778
            samplesPerPixel := 4.
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  3779
            bitsPerSample := #[8 8 8 8]
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3780
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3781
            d == 16 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3782
                samplesPerPixel := 3.
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  3783
                bitsPerSample := #[5 5 5].
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3784
                "/ bitsPerPixel := 15.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3785
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3786
                samplesPerPixel := 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3787
                bitsPerSample := ByteArray with:d
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3788
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3789
        ]
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3790
    ]
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3791
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  3792
    "Modified: / 27-05-2007 / 16:59:47 / cg"
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  3793
    "Modified: / 30-01-2017 / 19:36:00 / stefan"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3794
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3795
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3796
extent:anExtent
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3797
    "set the images extent.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3798
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3799
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3800
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3801
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3802
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3803
    width := anExtent x.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3804
    height := anExtent y
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3805
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3806
    "Modified: 23.4.1996 / 11:08:38 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3807
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3808
5326
0443d8649cac *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5319
diff changeset
  3809
hasAlphaChannel
0443d8649cac *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5319
diff changeset
  3810
    ^ false
0443d8649cac *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5319
diff changeset
  3811
!
0443d8649cac *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5319
diff changeset
  3812
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3813
height:aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3814
    "set the height of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3815
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3816
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3817
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3818
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3819
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3820
    height := aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3821
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3822
    "Modified: 23.4.1996 / 11:08:40 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3823
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3824
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3825
photometric:aSymbol
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3826
    "set the photometric interpretation of the pixel values.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3827
     The argument, aSymbol is one of:
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3828
        #blackIs0, #whiteIs0, #palette, #rgb
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3829
     See TIFF documentation, from which the photometric concept is borrowed.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3830
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3831
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3832
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3833
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3834
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3835
    |b|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3836
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3837
    photometric := aSymbol.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3838
    bitsPerSample isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3839
        photometric == #rgb ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3840
            b := self class imageDepth // 3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3841
            bitsPerSample := ByteArray with:b with:b with:b
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3842
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3843
            bitsPerSample := ByteArray with:(self class imageDepth)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3844
        ].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3845
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3846
    samplesPerPixel isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3847
        photometric == #rgb ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3848
            samplesPerPixel := 3
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3849
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3850
            samplesPerPixel := 1
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3851
        ]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3852
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3853
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3854
    "Modified: 10.6.1996 / 18:21:29 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3855
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3856
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3857
samplesPerPixel:aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3858
    "set the array of samples per pixel.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3859
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3860
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3861
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3862
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3863
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3864
    samplesPerPixel := aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3865
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3866
    "Modified: 23.4.1996 / 11:08:45 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3867
!
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3868
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3869
width:aNumber
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3870
    "set the width of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3871
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3872
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3873
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3874
     existing image may confuse later pixel interpretation."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3875
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3876
    width := aNumber
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3877
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3878
    "Modified: 23.4.1996 / 11:08:48 / cg"
100
1b0b86c77397 co !!:*
claus
parents: 89
diff changeset
  3879
!
1b0b86c77397 co !!:*
claus
parents: 89
diff changeset
  3880
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3881
width:w height:h
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3882
    "set the width and height of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3883
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3884
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3885
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3886
     existing image may confuse later pixel interpretation."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3887
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3888
    width := w.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3889
    height := h
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3890
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3891
    "Modified: 23.4.1996 / 11:08:53 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3892
!
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3893
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3894
width:w height:h depth:d
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3895
    "set the width, height and depth of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3896
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3897
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3898
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3899
     existing image may confuse later pixel interpretation."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3900
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3901
    width := w.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3902
    height := h.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3903
    self depth:d.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3904
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3905
    "Modified: 23.4.1996 / 11:08:56 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  3906
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  3907
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3908
width:w height:h depth:d fromArray:bits
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3909
    "set the width, height, depth and pixels of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3910
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3911
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3912
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3913
     existing image may confuse later pixel interpretation."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3914
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3915
    width := w.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3916
    height := h.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3917
    self depth:d.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3918
    self bits:bits
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3919
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3920
    "Modified: 23.4.1996 / 11:08:59 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3921
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3922
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3923
width:w height:h depth:d palette:aColormap
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3924
    "set the width, height and depth of the image.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3925
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3926
     This interface is only to be used when initializing
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3927
     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
  3928
     existing image may confuse later pixel interpretation."
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3929
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3930
    width := w.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3931
    height := h.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3932
    self depth:d.
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  3933
    self setColorMap:aColormap.
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3934
    aColormap notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3935
        photometric := #palette
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  3936
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3937
        photometric := #blackIs0
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  3938
    ].
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3939
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3940
    "Modified: 23.4.1996 / 11:08:56 / cg"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3941
    "Created: 6.3.1997 / 15:23:57 / cg"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3942
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3943
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3944
width:w height:h photometric:p
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3945
    "set the width, height and photometric of the image.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3946
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3947
     This interface is only to be used when initializing
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3948
     instances or by image readers. Calling for a change of an
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3949
     existing image may confuse later pixel interpretation."
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3950
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3951
    width := w.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3952
    height := h.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3953
    self photometric:p.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3954
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3955
    "Modified: 23.4.1996 / 11:08:56 / cg"
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3956
!
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3957
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3958
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
  3959
    "set all relevant internal state of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3960
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3961
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3962
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3963
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3964
894
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3965
    ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3966
        width:w
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3967
        height:h
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3968
        photometric:p
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3969
        samplesPerPixel:spp
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3970
        bitsPerSample:bps
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3971
        colorMap:cm
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3972
        bits:pixels
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3973
        mask:nil
894
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3974
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3975
    "Modified: 20.6.1996 / 17:10:24 / cg"
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3976
!
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3977
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3978
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
  3979
    "set all relevant internal state of the image.
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3980
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3981
     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
  3982
     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
  3983
     existing image may confuse later pixel interpretation."
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3984
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3985
    width := w.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3986
    height := h.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3987
    photometric := p.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3988
    samplesPerPixel := spp.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3989
    bitsPerSample := bps.
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  3990
    self setColorMap:cm.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3991
    self bits:pixels.
894
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3992
    mask := m.
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3993
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3994
    "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
  3995
    "Created: 20.6.1996 / 17:09:53 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3996
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
  3997
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  3998
2205
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3999
!Image methodsFor:'conversion helpers'!
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  4000
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  4001
rgbColormapFor:aDevice
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  4002
    "helper for conversion to rgb format"
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  4003
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  4004
    |nColors    "{ Class: SmallInteger }"
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  4005
     scaleRed scaleGreen scaleBlue
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  4006
     redShift   "{ Class: SmallInteger }"
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  4007
     greenShift "{ Class: SmallInteger }"
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  4008
     blueShift  "{ Class: SmallInteger }"
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  4009
     colorValues|
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  4010
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  4011
    "/ gather r/g/b values for all colors in the map ...
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  4012
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  4013
    nColors := 1 bitShift:(self depth).
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  4014
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  4015
    "/ precompute scales to map from 0..100 into devices range
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  4016
    "/ (this may be different for the individual components)
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  4017
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  4018
    scaleRed := ((1 bitShift:aDevice bitsRed) - 1) / 100.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  4019
    scaleGreen := ((1 bitShift:aDevice bitsGreen) - 1) / 100.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  4020
    scaleBlue := ((1 bitShift:aDevice bitsBlue) - 1) / 100.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  4021
    redShift := aDevice shiftRed.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  4022
    greenShift := aDevice shiftGreen.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  4023
    blueShift := aDevice shiftBlue.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  4024
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  4025
    colorValues := Array uninitializedNew:nColors.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  4026
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  4027
    0 to:nColors-1 do:[:pixel |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4028
        |clr rv gv bv v "{ Class: SmallInteger }" |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4029
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4030
        clr := self colorFromValue:pixel.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4031
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4032
        rv := (clr red * scaleRed) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4033
        gv := (clr green * scaleGreen) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4034
        bv := (clr blue * scaleBlue) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4035
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4036
        v := rv bitShift:redShift.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4037
        v := v bitOr:(gv bitShift:greenShift).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4038
        v := v bitOr:(bv bitShift:blueShift).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4039
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4040
        colorValues at:(pixel+1) put:v.
2205
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  4041
"/ clr print. ' ' print.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  4042
"/ rv print. ' ' print. gv print. ' ' print. bv print. ' ' print.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  4043
"/ ' -> ' print. v printNL.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  4044
    ].
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  4045
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  4046
    ^ colorValues
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  4047
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  4048
    "Modified: / 29.7.1998 / 00:34:56 / cg"
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  4049
! !
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  4050
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4051
!Image methodsFor:'converting'!
48194c26a46c Initial revision
claus
parents:
diff changeset
  4052
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4053
asBurkesDitheredMonochromeImage
837
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  4054
    "return a burkes dithered monochrome image from the receiver image.
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  4055
     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
  4056
     a floyd-steinberg dithered image.
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  4057
     Notice that floyd-steinberg dithering is faster; both because less
837
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  4058
     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
  4059
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4060
    |monoBits|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4061
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4062
    monoBits := self burkesDitheredMonochromeBits.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4063
    ^ 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
  4064
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4065
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4066
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4067
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4068
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4069
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4070
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4071
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4072
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4073
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4074
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4075
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4076
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4077
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4078
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4079
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4080
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4081
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4082
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4083
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4084
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4085
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4086
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4087
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4088
     i := Depth4Image
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  4089
             width:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  4090
             height:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  4091
             fromArray:#[
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  4092
                            16r01 16r23
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  4093
                            16r45 16r67
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  4094
                            16r89 16rab
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  4095
                            16rcd 16ref
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  4096
                        ].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4097
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4098
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4099
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4100
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4101
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4102
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4103
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4104
    "Created: 10.6.1996 / 12:34:44 / cg"
837
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  4105
    "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
  4106
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4107
3157
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  4108
asDitheredImageUsing:colors
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  4109
    "return a dithered image from the picture,
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  4110
     using colors in colors for dithering."
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  4111
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  4112
    ^ self asDitheredImageUsing:colors depth:self depth
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  4113
!
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  4114
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  4115
asDitheredImageUsing:colors depth:d
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  4116
    "return a dithered image from the picture,
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  4117
     using colors in colors for dithering."
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  4118
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  4119
    |newBits|
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  4120
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  4121
    newBits := self floydSteinbergDitheredDepth8BitsColors:colors map:(0 to:colors size - 1).
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3905
diff changeset
  4122
    newBits isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4123
        self error:'dithering failed'
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3905
diff changeset
  4124
    ].
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4125
    ^ (self class newForDepth:d) extent:(self extent); depth:d; palette:colors; bits:newBits; yourself
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4126
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4127
    "Modified: / 30-01-2017 / 19:40:19 / stefan"
3157
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  4128
!
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  4129
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4130
asErrorDitheredMonochromeImage
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4131
    "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
  4132
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4133
    DitherAlgorithm == #burkes ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4134
        ^ self asBurkesDitheredMonochromeImage
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4135
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4136
    DitherAlgorithm == #stevensonArce ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4137
        ^ self asStevensonArceDitheredMonochromeImage
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4138
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4139
    ^ self asFloydSteinbergDitheredMonochromeImage
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4140
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4141
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4142
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4143
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4144
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4145
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4146
     i asErrorDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4147
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4148
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4149
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4150
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4151
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4152
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4153
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4154
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4155
     i asErrorDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4156
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4157
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4158
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4159
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4160
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4161
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4162
     i := Depth4Image
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4163
             width:4
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4164
             height:4
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4165
             fromArray:#[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4166
                            16r01 16r23
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4167
                            16r45 16r67
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4168
                            16r89 16rab
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4169
                            16rcd 16ref
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4170
                        ].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4171
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4172
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4173
     i asErrorDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4174
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4175
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4176
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4177
    "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
  4178
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4179
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4180
asFloydSteinbergDitheredDepth8FormOn:aDevice colors:fixColors
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4181
    "return a floyd-steinberg dithered pseudoForm from the picture.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4182
     Use the colors in the fixColors array.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4183
     By passing the ditherColors as extra array, this method can
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4184
     also be used to dither an 8bit image into a smaller number of colors,
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4185
     for example to create dithered Depth4Images from Depth8Images."
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4186
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4187
    |pseudoBits f deviceDepth map|
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4188
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4189
    deviceDepth := aDevice depth.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4190
    deviceDepth == 8 ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4191
        (aDevice supportedImageFormatForDepth:8) isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4192
            ^ nil.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4193
        ]
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4194
    ].
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4195
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4196
    pseudoBits := self floydSteinbergDitheredDepth8BitsColors:fixColors.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4197
    pseudoBits isNil ifTrue:[^ nil].
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4198
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4199
    f := Form width:width height:height depth:deviceDepth onDevice:aDevice.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4200
    f isNil ifTrue:[^ nil].
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4201
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4202
    "/
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4203
    "/ have to create a funny colorMap, where
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4204
    "/ color at:index == color colorId:index
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4205
    "/
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4206
    map := Array new:256.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4207
    fixColors do:[:clr |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4208
        map at:clr colorId + 1 put:clr
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4209
    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4210
    f colorMap:map.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4211
    f bits:pseudoBits.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4212
    aDevice
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4213
        drawBits:pseudoBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4214
        bitsPerPixel:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4215
        depth:deviceDepth
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4216
        padding:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4217
        width:width height:height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4218
        x:0 y:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4219
        into:(f id) x:0 y:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4220
        width:width height:height
7755
75f5eba88e77 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7689
diff changeset
  4221
        with:(f initGC).
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4222
    ^ f
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4223
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4224
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4225
     example:
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4226
        color reduction from Depth8 to Depth4 (dithering) can be done by:
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4227
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4228
     |img8 reducedImg8 img4 map form|
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4229
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4230
     map := #(
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4231
                  (0     0   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4232
                  (0     0 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4233
                  (0    50   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4234
                  (0    50 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4235
                  (0   100   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4236
                  (0   100 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4237
                  (100   0   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4238
                  (100   0 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4239
                  (100  50   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4240
                  (100  50 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4241
                  (100 100   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4242
                  (100 100 100)) collect:[:rgb | (Color red:(rgb at:1)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4243
                                                      green:(rgb at:2)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4244
                                                       blue:(rgb at:3)) onDevice:Display].
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4245
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4246
     img8 := Image fromFile:'goodies/bitmaps/bf.im8'.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4247
     form := img8 paletteImageAsDitheredPseudoFormOn:Display
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4248
                      colors:map
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4249
                        nRed:2
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4250
                      nGreen:3
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4251
                       nBlue:2.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4252
     img8 := Depth8Image fromForm:form.    'dithered version of original image'.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4253
     img4 := Depth4Image fromImage:img8.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4254
    "
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4255
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4256
    "Modified: 14.6.1996 / 16:52:34 / cg"
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4257
    "Created: 23.6.1997 / 15:25:37 / cg"
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4258
!
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4259
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4260
asFloydSteinbergDitheredDepth8FormOn:aDevice colors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4261
    "return a floyd-steinberg dithered pseudoForm from the palette picture.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4262
     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
  4263
     colors assigned to aDevice, such as the preallocated colors of the
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4264
     Color class.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4265
     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
  4266
     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
  4267
     for example to create dithered Depth4Images from Depth8Images."
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4268
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4269
    |pseudoBits f deviceDepth map|
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4270
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4271
    deviceDepth := aDevice depth.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4272
    deviceDepth == 8 ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4273
        (aDevice supportedImageFormatForDepth:8) isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4274
            ^ nil
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4275
        ]
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4276
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4277
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4278
    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
  4279
    pseudoBits isNil ifTrue:[^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4280
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4281
    f := Form width:width height:height depth:deviceDepth onDevice:aDevice.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4282
    f isNil ifTrue:[^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4283
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4284
    "/
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4285
    "/ have to create a funny colorMap, where
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4286
    "/ color at:index == color colorId:index
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4287
    "/
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4288
    map := Array new:256.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4289
    fixColors do:[:clr |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4290
        map at:clr colorId + 1 put:clr
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4291
    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4292
    f colorMap:map.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4293
    f bits:pseudoBits.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4294
    aDevice
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4295
        drawBits:pseudoBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4296
        bitsPerPixel:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4297
        depth:deviceDepth
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4298
        padding:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4299
        width:width height:height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4300
        x:0 y:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4301
        into:(f id) x:0 y:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4302
        width:width height:height
7755
75f5eba88e77 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7689
diff changeset
  4303
        with:(f initGC).
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4304
    ^ f
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4305
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4306
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4307
     example:
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4308
        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
  4309
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4310
     |img8 reducedImg8 img4 map form|
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4311
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4312
     map := #(
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4313
                  (0     0   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4314
                  (0     0 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4315
                  (0    50   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4316
                  (0    50 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4317
                  (0   100   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4318
                  (0   100 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4319
                  (100   0   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4320
                  (100   0 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4321
                  (100  50   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4322
                  (100  50 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4323
                  (100 100   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4324
                  (100 100 100)) collect:[:rgb | (Color red:(rgb at:1)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4325
                                                      green:(rgb at:2)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4326
                                                       blue:(rgb at:3)) onDevice:Display].
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4327
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4328
     img8 := Image fromFile:'goodies/bitmaps/bf.im8'.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4329
     form := img8 paletteImageAsDitheredPseudoFormOn:Display
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4330
                      colors:map
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4331
                        nRed:2
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4332
                      nGreen:3
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4333
                       nBlue:2.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4334
     img8 := Depth8Image fromForm:form.    'dithered version of original image'.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4335
     img4 := Depth4Image fromImage:img8.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4336
    "
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4337
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4338
    "Modified: 14.6.1996 / 16:52:34 / cg"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4339
!
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4340
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4341
asFloydSteinbergDitheredGrayFormOn:aDevice
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4342
    "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
  4343
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4344
    |depth bits|
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4345
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4346
    depth := aDevice depth.
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4347
    (depth == 1
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4348
    or:[aDevice hasGrayscales not]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4349
        "/ for monochrome, there is specialized
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4350
        "/ monochrome dither code available
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4351
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4352
        bits := self floydSteinbergDitheredMonochromeBits.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4353
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4354
        bits := self floydSteinbergDitheredGrayBitsDepth:depth.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4355
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4356
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4357
    ^ 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
  4358
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4359
    "
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4360
     |i|
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4361
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4362
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4363
     (i asFloydSteinbergDitheredGrayFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4364
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4365
841
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  4366
    "
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4367
     |i|
841
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  4368
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  4369
     i := Image fromFile:'bitmaps/granite.tiff'.
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  4370
     (i asFloydSteinbergDitheredGrayFormOn:Display) inspect
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  4371
    "
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  4372
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4373
    "Created: 10.6.1996 / 14:11:39 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  4374
    "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
  4375
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4376
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4377
asFloydSteinbergDitheredGrayImageDepth:depth
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4378
    "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
  4379
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4380
    |ditheredBits|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4381
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4382
    (depth == 1) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4383
        ^ self asFloydSteinbergDitheredMonochromeImage
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4384
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4385
1779
34f9e24f330e method rename
Claus Gittinger <cg@exept.de>
parents: 1778
diff changeset
  4386
    ditheredBits := self floydSteinbergDitheredGrayBitsDepth:depth.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4387
    ^ (self class implementorForDepth:depth)
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4388
        width:width height:height fromArray:ditheredBits
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4389
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4390
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4391
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4392
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4393
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4394
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4395
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4396
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4397
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4398
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4399
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4400
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4401
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4402
829
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4403
     i := Depth24Image width:4 height:1
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4404
          fromArray:#[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4405
            16rFF 16r00 16r00   16rFF 16r00 16r00  16rFF 16r00 16r00  16rFF 16r00 16r00
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4406
            16rFF 16r00 16r00   16rFF 16r00 16r00  16rFF 16r00 16r00  16rFF 16r00 16r00
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4407
            16rFF 16r00 16r00   16rFF 16r00 16r00  16rFF 16r00 16r00  16rFF 16r00 16r00
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4408
            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
  4409
     i := i magnifiedBy:4@1.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4410
     i inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4411
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4412
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4413
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4414
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4415
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4416
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4417
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4418
     |i|
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4419
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4420
     i := Depth24Image width:4 height:6
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4421
          fromArray:#[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4422
            16r00 16r00 16r00   16r00 16r00 16r80  16r00 16r00 16rff  16r00 16r80 16r00
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4423
            16r00 16r80 16r80   16r00 16rFF 16r00  16r00 16rFF 16r80  16r00 16rFF 16rFF
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4424
            16r80 16r00 16r00   16r80 16r00 16r80  16r80 16r00 16rff  16r80 16r80 16r00
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4425
            16r80 16r80 16r80   16r80 16rFF 16r00  16r80 16rFF 16r80  16r80 16rFF 16rFF
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4426
            16rFF 16r00 16r00   16rFF 16r00 16r80  16rFF 16r00 16rff  16rFF 16r80 16r00
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4427
            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
  4428
     i := i magnifiedBy:30.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4429
     i inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4430
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4431
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4432
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4433
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4434
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4435
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4436
     |i|
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4437
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4438
     i := Image fromFile:'granite.tiff'.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4439
     i inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4440
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4441
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4442
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4443
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4444
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4445
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4446
     |i|
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4447
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4448
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4449
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4450
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4451
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4452
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4453
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4454
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4455
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4456
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4457
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4458
     i := Depth4Image
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4459
             width:4
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4460
             height:4
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4461
             fromArray:#[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4462
                            16r01 16r23
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4463
                            16r45 16r67
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4464
                            16r89 16rab
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4465
                            16rcd 16ref
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4466
                        ].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4467
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4468
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4469
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4470
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4471
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4472
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4473
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4474
    "Created: 10.6.1996 / 12:33:47 / cg"
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  4475
    "Modified: 19.10.1997 / 04:09:04 / cg"
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4476
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4477
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4478
asFloydSteinbergDitheredMonochromeFormOn:aDevice
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4479
    "return a dithered moncohrome form from the receiver image."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4480
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4481
    |monoBits|
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4482
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4483
    monoBits := self floydSteinbergDitheredMonochromeBits.
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4484
    ^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4485
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4486
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4487
     |i f|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4488
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4489
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4490
     (i asFloydSteinbergDitheredMonochromeFormOn:Display) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4491
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4492
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4493
    "
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4494
     |i f|
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4495
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4496
     i := Depth2Image width:8 height:8
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4497
          fromArray:#[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4498
                        4r0000 4r0000
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4499
                        4r0000 4r0000
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4500
                        4r1111 4r1111
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4501
                        4r1111 4r1111
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4502
                        4r2222 4r2222
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4503
                        4r2222 4r2222
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4504
                        4r3333 4r3333
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4505
                        4r3333 4r3333
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4506
                     ].
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4507
     (i asFloydSteinbergDitheredMonochromeFormOn:Display) inspect.
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4508
    "
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4509
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4510
    "Created: 10.6.1996 / 14:11:39 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  4511
    "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
  4512
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4513
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4514
asFloydSteinbergDitheredMonochromeImage
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4515
    "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
  4516
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4517
    |monoBits|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4518
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4519
    monoBits := self floydSteinbergDitheredMonochromeBits.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4520
    ^ 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
  4521
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4522
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4523
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4524
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4525
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4526
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4527
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4528
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4529
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4530
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4531
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4532
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4533
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4534
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4535
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4536
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4537
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4538
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4539
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4540
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4541
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4542
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4543
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4544
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4545
     i := Depth4Image
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4546
             width:4
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4547
             height:4
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4548
             fromArray:#[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4549
                            16r01 16r23
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4550
                            16r45 16r67
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4551
                            16r89 16rab
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4552
                            16rcd 16ref
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4553
                        ].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4554
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4555
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4556
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4557
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4558
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4559
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4560
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4561
    "Created: 10.6.1996 / 12:33:47 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  4562
    "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
  4563
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4564
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4565
asFloydSteinbergDitheredPseudoFormUsing:colors on:aDevice
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4566
    "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
  4567
     using colors in colors for dithering."
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4568
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4569
    |pseudoBits pseudoBits8 f has8BitImage deviceDepth map d|
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4570
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4571
    deviceDepth := aDevice depth.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4572
    has8BitImage := (deviceDepth == 8)
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4573
                    or:[ (aDevice supportedImageFormatForDepth:8) notNil ].
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4574
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  4575
    has8BitImage ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4576
        deviceDepth == 4 ifFalse:[^ nil].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4577
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4578
        pseudoBits8 := self nfloydSteinbergDitheredDepth8BitsColors:colors.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4579
        pseudoBits8 isNil ifTrue:[^ nil].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4580
        "/ convert to devices depth
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4581
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4582
        pseudoBits := ByteArray new:(width*4+7//8 * height).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4583
        pseudoBits8 compressPixels:4 width:width height:height into:pseudoBits mapping:nil.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4584
        d := 4.
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  4585
    ] ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4586
        pseudoBits := self nfloydSteinbergDitheredDepth8BitsColors:colors.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4587
        pseudoBits isNil ifTrue:[^ nil].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4588
        d := 8.
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4589
    ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4590
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4591
    f := Form width:width height:height depth:deviceDepth onDevice:aDevice.
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4592
    f isNil ifTrue:[^ nil].
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4593
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4594
    "/
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4595
    "/ have to create a funny colorMap, where
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4596
    "/ color at:index == color colorId:index
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4597
    "/
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4598
    map := Array new:256 withAll:0.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4599
    colors do:[:clr |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4600
        clr notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4601
            map at:clr colorId + 1 put:clr
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4602
        ]
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4603
    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4604
    f colorMap:map.
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4605
    f bits:pseudoBits.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4606
    aDevice
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4607
        drawBits:pseudoBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4608
        bitsPerPixel:d
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4609
        depth:deviceDepth
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4610
        padding:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4611
        width:width height:height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4612
        x:0 y:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4613
        into:(f id) x:0 y:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4614
        width:width height:height
7755
75f5eba88e77 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7689
diff changeset
  4615
        with:(f initGC).
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4616
    ^ f
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4617
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4618
    "
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4619
     |i|
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4620
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4621
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4622
     (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
  4623
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4624
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4625
     |i|
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4626
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4627
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4628
     (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
  4629
    "
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4630
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4631
    "Created: 17.6.1996 / 12:13:35 / cg"
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  4632
    "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
  4633
!
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4634
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4635
asFormOn:aDevice
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4636
    "get a device form, with best possible approximation.
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4637
     remember it in case someone asks again."
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4638
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  4639
    |form visual|
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4640
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4641
    ((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ deviceForm].
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4642
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
  4643
    mask notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4644
        mask := mask onDevice:aDevice
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4645
    ].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4646
    bytes isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4647
        pixelFunction notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4648
            self computeBitsFromPixelFunction.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4649
        ]
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
  4650
    ].
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
  4651
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4652
    (aDevice depth == 1
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4653
    or:[aDevice hasGrayscales not]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4654
        form := self asMonochromeFormOn:aDevice.
2212
ddc9cb6aeb73 more caching if device forms.
Claus Gittinger <cg@exept.de>
parents: 2206
diff changeset
  4655
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4656
        ((visual := aDevice visualType) == #StaticGray) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4657
            form := self asGrayFormOn:aDevice.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4658
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4659
            (visual == #PseudoColor
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4660
             or:[visual == #StaticColor]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4661
                form := self asPseudoFormQuickOn:aDevice.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4662
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4663
        ]
2212
ddc9cb6aeb73 more caching if device forms.
Claus Gittinger <cg@exept.de>
parents: 2206
diff changeset
  4664
    ].
ddc9cb6aeb73 more caching if device forms.
Claus Gittinger <cg@exept.de>
parents: 2206
diff changeset
  4665
ddc9cb6aeb73 more caching if device forms.
Claus Gittinger <cg@exept.de>
parents: 2206
diff changeset
  4666
    form isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4667
        "/ kludge: repair a 'should not happen' situation...
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4668
        photometric isNil ifTrue:[ self repairPhotometric ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4669
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4670
        (photometric == #palette) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4671
            form := self paletteImageAsFormOn:aDevice
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4672
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4673
            (photometric == #rgb or:[photometric == #rgba or:[photometric == #argb]]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4674
                form := self rgbImageAsFormOn:aDevice
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4675
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4676
                (photometric == #cmy or:[photometric == #cmyk]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4677
                    form := self rgbImageAsFormOn:aDevice
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4678
                ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4679
                    form := self greyImageAsFormOn:aDevice
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4680
                ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4681
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4682
        ].
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4683
    ].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4684
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4685
    (device isNil or:[aDevice == device]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4686
        "remember this form in the receiver ..."
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4687
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4688
        form notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4689
            form := form asImageForm.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4690
            deviceForm := form.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4691
            maskedPixelsAre0 := nil.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4692
            device isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4693
                device := aDevice.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4694
                Lobby register:self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4695
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4696
                Lobby registerChange:self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4697
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4698
            mask notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4699
                self clearMaskedPixels.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4700
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4701
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4702
            "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4703
             can save space, by not keeping the images data-bits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4704
             twice (here and in the device form)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4705
            "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4706
            form forgetBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4707
        ]
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4708
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
  4709
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4710
    ^ form
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4711
4173
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  4712
    "
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  4713
     |i|
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  4714
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  4715
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  4716
     (i asFormOn:Display) inspect.
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  4717
    "
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  4718
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4719
    "Modified: / 06-06-2007 / 12:18:43 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4720
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4721
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4722
asGrayFormOn:aDevice
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4723
    "get a gray device form"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4724
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4725
    ^ self asGrayFormOn:aDevice dither:DitherAlgorithm.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4726
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4727
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4728
     |i|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4729
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4730
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4731
     (i asGrayFormOn:Display) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4732
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4733
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4734
    "Modified: 10.6.1996 / 17:39:30 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4735
    "Created: 10.6.1996 / 18:44:42 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4736
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4737
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4738
asGrayFormOn:aDevice dither:aDitherAlgorithm
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4739
    "get a greyscale device form, using aDitherAlgorithm."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4740
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4741
    |depth|
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4742
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4743
    depth := aDevice depth.
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4744
    (depth == 1
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4745
    or:[aDevice hasGrayscales not]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4746
        ^ self asMonochromeFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4747
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4748
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4749
    (aDitherAlgorithm isNil
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4750
    or:[aDitherAlgorithm == #threshold]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4751
        ^ self asThresholdGrayFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4752
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4753
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4754
    (aDitherAlgorithm == #pattern
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4755
    or:[aDitherAlgorithm == #ordered]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4756
        ^ self asOrderedDitheredGrayFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4757
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4758
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4759
    ^ self asFloydSteinbergDitheredGrayFormOn:aDevice.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4760
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4761
    "Created: 10.6.1996 / 18:42:01 / cg"
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  4762
    "Modified: 14.6.1996 / 15:17:28 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4763
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4764
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4765
asGrayImageDepth:depthArg
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4766
    "get a gray image from the receiver"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4767
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4768
    ((self colorMap notNil and:[depthArg between:self depth and:8])
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4769
     or:[self depth >= 8 "do need for dither" ]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4770
        ^ self copyWithColorMapProcessing:[:clr | Color brightness:(clr brightness)].
4417
5e5d9b696293 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  4771
    ].
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4772
    ^ self asGrayImageDepth:depthArg dither:DitherAlgorithm.
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4773
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4774
    "
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4775
     |i|
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4776
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4777
     i := Image fromFile:'../../goodies/bitmaps/gifImages/claus.gif'.
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4778
     (i asGrayImageDepth:16).
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4779
     (i asGrayImageDepth:4).
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4780
    "
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4781
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4782
    "Modified: / 10-06-1996 / 17:39:30 / cg"
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4783
    "Created: / 10-06-1996 / 19:07:08 / cg"
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4784
    "Modified: / 30-01-2017 / 20:13:06 / stefan"
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4785
    "Modified (comment): / 31-01-2017 / 13:25:29 / stefan"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4786
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4787
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4788
asGrayImageDepth:depth dither:aDitherAlgorithm
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4789
    "get a greyscale image, using aDitherAlgorithm."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4790
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4791
    (aDitherAlgorithm isNil
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4792
    or:[aDitherAlgorithm == #threshold]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4793
        ^ self asThresholdGrayImageDepth:depth
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4794
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4795
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4796
    (aDitherAlgorithm == #pattern
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4797
    or:[aDitherAlgorithm == #ordered]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4798
        ^ self asOrderedDitheredGrayImageDepth:depth
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4799
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4800
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4801
    ^ self asFloydSteinbergDitheredGrayImageDepth:depth
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4802
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4803
    "Created: 10.6.1996 / 19:08:21 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4804
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  4805
4423
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4806
asImageWithDepth:depth
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4807
    "return a new image with another depth. Notice that this
7242
bf3a75233d55 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7230
diff changeset
  4808
     may raise an error, if the depth is smaller than the receiver's depths
4423
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4809
     and the number of colors is greater than the number of possible colors
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4810
     for the new depth - i.e. you should use this only to convert to a higher depth.
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4811
     In the other case, use one of the dithering converters"
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4812
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4813
    |imageClass|
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4814
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4815
    imageClass := Image implementorForDepth:depth.
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4816
    ^ imageClass fromImage:self
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4817
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4818
    "
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4819
     |i|
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4820
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4821
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4822
     (i asImageWithDepth:24) inspect.
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4823
    "
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4824
    "
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4825
     |i|
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4826
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4827
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4828
     (i asImageWithDepth:4) inspect.
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4829
    "
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4830
!
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4831
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4832
asMonochromeFormOn:aDevice
48194c26a46c Initial revision
claus
parents:
diff changeset
  4833
    "get a monochrome device form"
48194c26a46c Initial revision
claus
parents:
diff changeset
  4834
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4835
    |form|
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4836
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4837
    ((aDevice == device) and:[monoDeviceForm notNil]) ifTrue:[^ monoDeviceForm].
4390
8d752f4cd9e2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  4838
    self depth == 1 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4839
        ((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ deviceForm].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4840
        ^ self asFormOn:aDevice
1935
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
  4841
    ].
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4842
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4843
    form := self asMonochromeFormOn:aDevice dither:DitherAlgorithm.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4844
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4845
    (device isNil or:[aDevice == device]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4846
        "remember this form in the receiver ..."
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4847
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4848
        form notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4849
            form := form asImageForm.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4850
            monoDeviceForm := form.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4851
            device isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4852
                device := aDevice.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4853
                Lobby register:self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4854
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4855
                Lobby registerChange:self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4856
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4857
            "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4858
             can save space, by not keeping the images data-bits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4859
             twice (here and in the device form)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4860
            "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4861
            form forgetBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4862
        ]
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4863
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
  4864
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4865
    ^ form
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4866
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4867
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4868
     |i|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4869
4173
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  4870
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4871
     (i asMonochromeFormOn:Display) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4872
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4873
1935
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
  4874
    "Modified: 23.10.1997 / 00:44:59 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4875
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4876
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4877
asMonochromeFormOn:aDevice dither:aDitherAlgorithm
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4878
    "get a monochrome device form, using aDitherAlgorithm."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4879
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4880
    |monoBits|
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4881
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4882
    (aDitherAlgorithm isNil
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4883
    or:[aDitherAlgorithm == #threshold]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4884
        ^ self asThresholdMonochromeFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4885
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4886
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4887
    aDitherAlgorithm == #burkes ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4888
        monoBits := self burkesDitheredMonochromeBits.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4889
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4890
        aDitherAlgorithm == #stevensonArce ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4891
            monoBits := self stevensonArceDitheredMonochromeBits.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4892
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4893
            (aDitherAlgorithm == #pattern
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4894
            or:[aDitherAlgorithm == #ordered]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4895
                ^ self asOrderedDitheredGrayFormOn:aDevice.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4896
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4897
                ^ self asFloydSteinbergDitheredMonochromeFormOn:aDevice.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4898
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4899
        ]
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4900
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4901
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4902
    "/
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4903
    "/ make its pixel interpretation correct for the device
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4904
    "/
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4905
    ^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4906
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4907
    "Modified: 10.6.1996 / 20:18:05 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4908
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4909
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4910
asNearestPaintDepth8FormOn:aDevice colors:fixColors
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4911
    "return a nearest paint pseudoForm from the palette picture.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4912
     Use the colors in the fixColors array.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4913
     By passing the ditherColors as extra array, this method can
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4914
     also be used to dither an 8bit image into a smaller number of colors,
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4915
     for example to create dithered Depth4Images from Depth8Images."
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4916
3914
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4917
    ^ self asNearestPaintDepth8FormOn:aDevice colors:fixColors nRed:nil nGreen:nil nBlue:nil.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4918
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4919
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4920
     example:
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4921
        color reduction from Depth8 to Depth4 can be done by:
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4922
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4923
     |img8 reducedImg8 img4 map form|
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4924
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4925
     map := #(
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4926
                  (0     0   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4927
                  (0     0 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4928
                  (0    50   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4929
                  (0    50 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4930
                  (0   100   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4931
                  (0   100 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4932
                  (100   0   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4933
                  (100   0 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4934
                  (100  50   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4935
                  (100  50 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4936
                  (100 100   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4937
                  (100 100 100)) collect:[:rgb | (Color red:(rgb at:1)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4938
                                                      green:(rgb at:2)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4939
                                                       blue:(rgb at:3)) onDevice:Display].
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4940
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4941
     img8 := Image fromFile:'goodies/bitmaps/claus.gif'.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4942
     form := img8 asNearestPaintDepth8FormOn:Display
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4943
                      colors:map
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4944
                        nRed:2
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4945
                      nGreen:3
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4946
                       nBlue:2.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4947
     img8 := Depth8Image fromForm:form.    'dithered version of original image'.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4948
     img4 := Depth4Image fromImage:img8.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4949
    "
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4950
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4951
    "Modified: 17.6.1996 / 18:52:47 / cg"
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4952
    "Created: 23.6.1997 / 15:26:09 / cg"
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4953
!
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4954
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4955
asNearestPaintDepth8FormOn:aDevice colors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4956
    "return a nearest paint pseudoForm from the palette picture.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4957
     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
  4958
     colors assigned to aDevice, such as the preallocated colors of the
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4959
     Color class.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4960
     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
  4961
     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
  4962
     for example to create dithered Depth4Images from Depth8Images."
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4963
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4964
    |pseudoBits f deviceDepth map|
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4965
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4966
    deviceDepth := aDevice depth.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4967
    deviceDepth == 8 ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4968
        (aDevice supportedImageFormatForDepth:8) isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4969
            ^ nil
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4970
        ]
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4971
    ].
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4972
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4973
    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
  4974
    pseudoBits isNil ifTrue:[^ nil].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4975
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4976
    f := Form width:width height:height depth:deviceDepth onDevice:aDevice.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4977
    f isNil ifTrue:[^ nil].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4978
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4979
    "/
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4980
    "/ have to create a funny colorMap, where
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4981
    "/ color at:index == color colorId:index
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4982
    "/
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4983
    map := Array new:256.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4984
    fixColors do:[:clr |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4985
        map at:clr colorId + 1 put:clr
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4986
    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4987
    f colorMap:map.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4988
    f bits:pseudoBits.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4989
    aDevice
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4990
        drawBits:pseudoBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4991
        bitsPerPixel:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4992
        depth:deviceDepth
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4993
        padding:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4994
        width:width height:height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4995
        x:0 y:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4996
        into:(f id) x:0 y:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4997
        width:width height:height
7755
75f5eba88e77 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7689
diff changeset
  4998
        with:(f initGC).
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4999
    ^ f
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  5000
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  5001
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5002
     example:
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5003
        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
  5004
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  5005
     |img8 reducedImg8 img4 map form|
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  5006
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5007
     map := #(
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5008
                  (0     0   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5009
                  (0     0 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5010
                  (0    50   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5011
                  (0    50 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5012
                  (0   100   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5013
                  (0   100 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5014
                  (100   0   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5015
                  (100   0 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5016
                  (100  50   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5017
                  (100  50 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5018
                  (100 100   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5019
                  (100 100 100)) collect:[:rgb | (Color red:(rgb at:1)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5020
                                                      green:(rgb at:2)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5021
                                                       blue:(rgb at:3)) onDevice:Display].
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5022
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5023
     img8 := Image fromFile:'goodies/bitmaps/claus.gif'.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5024
     form := img8 asNearestPaintDepth8FormOn:Display
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5025
                      colors:map
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5026
                        nRed:2
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5027
                      nGreen:3
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5028
                       nBlue:2.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  5029
     img8 := Depth8Image fromForm:form.    'dithered version of original image'.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  5030
     img4 := Depth4Image fromImage:img8.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  5031
    "
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  5032
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  5033
    "Created: 17.6.1996 / 18:47:46 / cg"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  5034
    "Modified: 17.6.1996 / 18:52:47 / cg"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  5035
!
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  5036
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5037
asNearestPaintImageDepth:d colors:colors
3914
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  5038
    "return a threshold image from the receiver picture, using colors in colors."
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  5039
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  5040
    |newBits|
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  5041
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  5042
    d ~~ 8 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5043
        self error:'unsupported depth'
3914
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  5044
    ].
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  5045
    newBits := self nearestPaintDepth8BitsColors:colors nRed:nil nGreen:nil nBlue:nil.
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  5046
    newBits isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5047
        self error:'conversion failed'
3914
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  5048
    ].
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  5049
    ^ (self class newForDepth:d) extent:(self extent); depth:d; palette:colors; bits:newBits; yourself
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  5050
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  5051
    "Modified: / 30-01-2017 / 19:40:28 / stefan"
3914
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  5052
!
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  5053
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5054
asOrderedDitheredGrayFormOn:aDevice
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5055
    "return a dithered depth-x grey form from the receiver image.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5056
     Uses an 8x8 dithermatrix."
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5057
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  5058
    |depth bits|
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5059
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5060
    depth := aDevice depth.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5061
    (depth == 1
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  5062
    or:[aDevice hasGrayscales not]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5063
        "/ for monochrome, there is highly specialized
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5064
        "/ monochrome dither code available
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5065
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5066
        ^ self asOrderedDitheredMonochromeFormOn:aDevice
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5067
    ].
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5068
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5069
    bits := self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5070
                orderedDitheredGrayBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5071
                ditherWidth:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5072
                depth:depth.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5073
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  5074
    ^ self makeDeviceGrayPixmapOn:aDevice depth:depth fromArray:bits
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5075
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5076
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5077
     |i|
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5078
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5079
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5080
     (i asOrderedDitheredGrayFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5081
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5082
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  5083
    "Modified: 24.6.1997 / 22:19:30 / cg"
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5084
!
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5085
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5086
asOrderedDitheredGrayImageDepth:depth
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5087
    "return a dithered depth-x grey image from the receiver image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5088
     Uses an 8x8 dithermatrix."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5089
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5090
    |dither|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5091
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5092
    dither := self class orderedDitherMatrixOfSize:8.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5093
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  5094
    (depth == 1) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5095
        "/ for monochrome, there is highly specialized
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5096
        "/ monochrome dither code available
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5097
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5098
        ^ Depth1Image
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5099
            width:width
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5100
            height:height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5101
            fromArray:(
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5102
                self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5103
                    orderedDitheredMonochromeBitsWithDitherMatrix:dither
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5104
                    ditherWidth:8)
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5105
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5106
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5107
    ^ (self class implementorForDepth:depth)
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5108
        width:width
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5109
        height:height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5110
        fromArray:(
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5111
            self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5112
                orderedDitheredGrayBitsWithDitherMatrix:dither
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5113
                ditherWidth:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5114
                depth:depth)
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5115
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5116
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5117
     |i i1 i2 i4 i8|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5118
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5119
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5120
     i1 := i asOrderedDitheredGrayImageDepth:1.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5121
     i1 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5122
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5123
     i2 := i asOrderedDitheredGrayImageDepth:2.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5124
     i2 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5125
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5126
     i4 := i asOrderedDitheredGrayImageDepth:4.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5127
     i4 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5128
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5129
     i8 := i asOrderedDitheredGrayImageDepth:8.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5130
     i8 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5131
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5132
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5133
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5134
     |i i1 i2 i4 i8|
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5135
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5136
     i1 := i asOrderedDitheredGrayImageDepth:1.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5137
     i1 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5138
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5139
     i2 := i asOrderedDitheredGrayImageDepth:2.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5140
     i2 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5141
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5142
     i4 := i asOrderedDitheredGrayImageDepth:4.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5143
     i4 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5144
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5145
     i8 := i asOrderedDitheredGrayImageDepth:8.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5146
     i8 inspect.
800
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  5147
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  5148
     i2 := i8 asOrderedDitheredGrayImageDepth:2.
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  5149
     i2 inspect.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5150
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5151
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5152
    "Created: 7.6.1996 / 18:03:54 / cg"
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  5153
    "Modified: 24.6.1997 / 22:19:36 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5154
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5155
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5156
asOrderedDitheredMonochromeFormOn:aDevice
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5157
    "return a dithered monochrome form from the grey image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5158
     Uses a 4x4 dithermatrix."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5159
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5160
    "/ 4x4 seems a good comprimize between:
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5161
    "/    number of grey levels (8x8 is better)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5162
    "/    artifacts             (4x4 is better)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5163
    "/
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5164
    "/ could look at the image and decide upon the number of
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5165
    "/ distinct colors present. Use 8x8 for high-number,
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5166
    "/ 4x4 for small number of colors ...
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5167
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5168
    ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5169
        asOrderedDitheredMonochromeFormOn:aDevice
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5170
        ditherMatrix:(self class orderedDitherMatrixOfSize:4)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5171
        ditherWidth:4
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5172
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5173
"/    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5174
"/        asOrderedDitheredMonochromeFormOn:aDevice
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5175
"/        ditherMatrix:(self class orderedDitherMatrixOfSize:8)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5176
"/        ditherWidth:8
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5177
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5178
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5179
     |i f|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5180
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5181
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5182
     f := i asOrderedDitheredMonochromeFormOn:Display.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5183
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5184
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5185
     |i f|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5186
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5187
     i := (Image fromFile:'goodies/bitmaps/winBitmaps/a11.ico') magnifiedBy:10.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5188
     f := i asOrderedDitheredMonochromeFormOn:Display.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5189
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5190
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5191
     |i f|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5192
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5193
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5194
     f := i asOrderedDitheredMonochromeFormOn:Display.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5195
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5196
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5197
     |i f|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5198
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5199
     i := (Image fromFile:'doc/online/pictures/PasteButton.gif') magnifiedBy:10.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5200
     f := i asOrderedDitheredMonochromeFormOn:Display.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5201
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5202
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5203
     |i f|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5204
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5205
     i := (Image fromFile:'goodies/bitmaps/gifImages/blue-ball.gif') magnifiedBy:1.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5206
     f := i asOrderedDitheredMonochromeFormOn:Display.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5207
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5208
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5209
    "Created: 7.6.1996 / 14:52:32 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  5210
    "Modified: 17.4.1997 / 01:10:10 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5211
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5212
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5213
asOrderedDitheredMonochromeFormOn:aDevice ditherMatrix:ditherMatrix ditherWidth:dW
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5214
    "return a dithered monochrome form from the image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5215
     Uses the passed ditherMatrix and ditherWidth."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5216
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  5217
    |monoBits|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5218
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5219
    monoBits := self orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW.
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  5220
    ^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5221
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5222
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5223
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5224
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5225
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5226
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5227
     (i asOrderedDitheredMonochromeFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5228
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5229
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5230
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5231
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5232
     i := Image fromFile:'goodies/bitmaps/granite.tiff'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5233
     (i asOrderedDitheredMonochromeFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5234
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5235
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5236
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5237
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5238
     i := (Image fromFile:'goodies/bitmaps/PasteButton.tiff') magnifiedBy:10.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5239
     (i asOrderedDitheredMonochromeFormOn:Display) inspect
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5240
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5241
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5242
    "Created: 7.6.1996 / 14:51:42 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  5243
    "Modified: 17.4.1997 / 01:08:24 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5244
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5245
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5246
asOrderedDitheredMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5247
    "return a dithered monochrome image from the receiver image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5248
     Uses a 4x4 dithermatrix."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5249
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5250
    "/ 4x4 seems a good comprimize between:
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5251
    "/    number of grey levels (8x8 is better)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5252
    "/    artifacts             (4x4 is better)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5253
    "/
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5254
    "/ could look at the image and decide upon the number of
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5255
    "/ distinct colors present. Use 8x8 for high-number,
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5256
    "/ 4x4 for small number of colors ...
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5257
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5258
    ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5259
        asOrderedDitheredMonochromeImageWithDitherMatrix:(self class orderedDitherMatrixOfSize:4)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5260
        ditherWidth:4
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5261
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5262
"/    ^ self
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5263
"/        asOrderedDitheredMonochromeImageWithDitherMatrix:(self class orderedDitherMatrixOfSize:8)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5264
"/        ditherWidth:8
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5265
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5266
    "
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5267
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5268
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5269
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5270
     i asOrderedDitheredMonochromeImage inspect
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5271
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5272
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5273
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5274
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5275
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5276
     i asOrderedDitheredMonochromeImage inspect
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5277
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5278
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5279
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5280
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5281
     i := (Image fromFile:'doc/online/pictures/PasteButton.gif') magnifiedBy:10.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5282
     i asOrderedDitheredMonochromeImage inspect
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5283
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5284
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5285
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5286
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5287
     i := (Image fromFile:'goodies/bitmaps/gifImages/blue-ball.gif') magnifiedBy:1.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5288
     i asOrderedDitheredMonochromeImage inspect
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5289
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5290
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5291
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5292
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5293
     i := Image fromFile:'libwidg3/bitmaps/granite.tiff'.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5294
     i asOrderedDitheredMonochromeImage inspect
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5295
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5296
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5297
    "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
  5298
    "Modified: 10.6.1996 / 11:15:09 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5299
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5300
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5301
asOrderedDitheredMonochromeImageWithDitherMatrix:ditherMatrix ditherWidth:dW
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5302
    "return a dithered monochrome image from the receiver image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5303
     Uses the passed ditherMatrix and ditherWidth."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5304
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5305
    |monoBits|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5306
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5307
    monoBits := self orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5308
    ^ (Depth1Image width:width height:height fromArray:monoBits) photometric:#blackIs0
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5309
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5310
    "order-4 dither:
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5311
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5312
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5313
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5314
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5315
     i
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5316
        asOrderedDitheredMonochromeImageWithDitherMatrix:(Image orderedDitherMatrixOfSize:4)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5317
        ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5318
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5319
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5320
    "order-6 dither:
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5321
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5322
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5323
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5324
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5325
     i
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5326
        asOrderedDitheredMonochromeImageWithDitherMatrix:(Image orderedDitherMatrixOfSize:8)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5327
        ditherWidth:8
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5328
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5329
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5330
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5331
    "thresholding at:0.5 (all above 0.5 becomes white):
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5332
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5333
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5334
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5335
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5336
     i
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5337
        asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:8)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5338
        ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5339
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5340
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5341
    "thresholding at: 0.25 (all above 0.25 becomes white):
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5342
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5343
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5344
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5345
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5346
     i
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5347
        asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:3)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5348
        ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5349
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5350
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5351
    "thresholding at: 0.75 (all above 0.75 becomes white):
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5352
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5353
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5354
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5355
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5356
     i
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5357
        asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:11)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5358
        ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5359
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5360
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5361
    "Modified: 7.6.1996 / 17:23:47 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5362
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5363
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5364
asPseudoFormQuickOn:aDevice
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5365
    "return a pseudo-deviceForm from the image.
878
b99add8dc742 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 874
diff changeset
  5366
     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
  5367
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5368
    |f d
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5369
     temp temp8 bits clr cMap idMap
2772
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  5370
     w            "{ Class: SmallInteger }"
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  5371
     h            "{ Class: SmallInteger }"
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  5372
     dDev         "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5373
     nClr         "{ Class: SmallInteger }"
2772
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  5374
     bytesPerLine "{ Class: SmallInteger }"
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  5375
     usedColors pix fmt bytes|
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5376
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5377
    d := self depth.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5378
    (d == 1
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5379
    or:[d == 2
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5380
    or:[d == 4
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5381
    or:[d == 8]]]) ifFalse:[^ nil].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5382
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  5383
    bytes := self bits.
2772
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  5384
    w := width.
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  5385
    h := height.
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  5386
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5387
    "/ for now (since the code below does not care for padding;
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5388
    "/ if the padding is not supported: fail
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5389
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5390
    dDev := aDevice depth.
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5391
    (bytesPerLine := dDev) == 8 ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5392
        bytesPerLine := (w * dDev + 7) // 8.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5393
    ].
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5394
2532
Claus Gittinger <cg@exept.de>
parents: 2530
diff changeset
  5395
    fmt := aDevice supportedImageFormatForDepth:dDev.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5396
    fmt isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5397
        "/ cannot draw directly
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5398
        ^ nil
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5399
    ].
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5400
    (bytesPerLine * 8) \\ (fmt at:#padding) == 0 ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5401
        "/ mhmh - ought to repad here;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5402
        "/ however, the nonQuick converter does it.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5403
        ^ nil
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5404
    ].
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5405
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5406
    "/ see if all of the images colors are representable
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5407
    "/ on the device
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5408
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5409
    bits := self bitsPerPixel.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5410
    nClr := (1 bitShift:bits).
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5411
    cMap := Array new:nClr.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5412
    idMap := ByteArray new:nClr.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5413
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5414
    photometric == #palette ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5415
        nClr := nClr min:(colorMap size)
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5416
    ].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5417
878
b99add8dc742 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 874
diff changeset
  5418
    d == 8 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5419
        usedColors := bytes usedValues.    "gets us an array filled with used values"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5420
        1 to:nClr do:[:pixel |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5421
            (usedColors includes:(pixel - 1)) ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5422
                clr := Color black
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5423
            ] ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5424
                clr := self colorFromValue:pixel-1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5425
                clr := clr exactOn:aDevice.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5426
                clr isNil ifTrue:[^ nil].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5427
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5428
            (pix := clr colorId) isNil ifTrue:[^ nil].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5429
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5430
            cMap at:(pixel) put:clr.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5431
            idMap at:(pixel) put:pix.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5432
        ].
878
b99add8dc742 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 874
diff changeset
  5433
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5434
        1 to:nClr do:[:pixel |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5435
            clr := self colorFromValue:pixel-1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5436
            clr := clr exactOn:aDevice.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5437
            clr isNil ifTrue:[^ nil].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5438
            (pix := clr colorId) isNil ifTrue:[^ nil].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5439
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5440
            cMap at:(pixel) put:clr.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5441
            idMap at:(pixel) put:pix.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5442
        ].
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5443
    ].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5444
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5445
    "/ got all colors; good - simply change depth & translate pixels
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5446
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5447
    (d == 8 and:[dDev == 8]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5448
        "/ only translate
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5449
        temp := ByteArray uninitializedNew:(w * h).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5450
        bytes expandPixels:8         "xlate only"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5451
                    width:w
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5452
                   height:h
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5453
                     into:temp
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5454
                  mapping:idMap.
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5455
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5456
        "/ stupid: expandPixels can only handle any-to-8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5457
        "/ compressPixels can only handle 8-to-any
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5458
        "/ However, those methods are faster
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5459
        "/ - even if we convert twice.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5460
        "/ Therefore, convert first from myDepth to 8,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5461
        "/ then from 8 to the device depth.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5462
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5463
        d ~~ 8 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5464
            temp8 := ByteArray uninitializedNew:(w * h).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5465
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5466
            bytes expandPixels:d
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5467
                         width:w
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5468
                        height:h
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5469
                          into:temp8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5470
                       mapping:idMap.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5471
            idMap := nil.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5472
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5473
            temp8 := bytes.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5474
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5475
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5476
        dDev ~~ 8 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5477
            temp := ByteArray uninitializedNew:(bytesPerLine * h).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5478
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5479
            temp8 compressPixels:dDev
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5480
                         width:w
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5481
                        height:h
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5482
                          into:temp
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5483
                       mapping:idMap.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5484
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5485
            temp := temp8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5486
        ].
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5487
    ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5488
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5489
    f := Form width:w height:h depth:dDev onDevice:aDevice.
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5490
    f isNil ifTrue:[^ nil].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5491
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5492
    f colorMap:cMap.
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5493
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5494
    aDevice
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5495
        drawBits:temp
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5496
        depth:dDev
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5497
        padding:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5498
        width:w
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5499
        height:h
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5500
        x:0 y:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5501
        into:(f id) x:0 y:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5502
        width:w
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5503
        height:h
7755
75f5eba88e77 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7689
diff changeset
  5504
        with:(f initGC).
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5505
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5506
    ^ f
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5507
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5508
    "
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5509
     (
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5510
        (((Depth4Image
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5511
             width:4
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5512
             height:4
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5513
             fromArray:#[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5514
                            16r01 16r23
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5515
                            16r45 16r67
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5516
                            16r89 16rab
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5517
                            16rcd 16ref
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5518
                        ]))
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5519
               magnifiedBy:30
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5520
         )
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5521
          asPseudoFormQuickOn:Display
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5522
      ) inspect
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5523
     "
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5524
2113
c64f89f9ffba checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2102
diff changeset
  5525
    "Modified: / 7.5.1998 / 19:40:47 / cg"
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5526
!
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5527
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5528
asStevensonArceDitheredMonochromeImage
837
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  5529
    "return a stevenson-arce dithered monochrome image from the receiver image.
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  5530
     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
  5531
     a floyd-steinberg dithered image.
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  5532
     Notice that floyd-steinberg dithering is faster; both because less
837
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  5533
     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
  5534
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5535
    |monoBits|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5536
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5537
    monoBits := self stevensonArceDitheredMonochromeBits.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5538
    ^ (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
  5539
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5540
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5541
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5542
5161
d6538957b675 changed #asStevensonArceDitheredMonochromeImage
sr
parents: 5160
diff changeset
  5543
     i := Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif'.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5544
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5545
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5546
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5547
     i asStevensonArceDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5548
     i asOrderedDitheredMonochromeImage inspect.
5161
d6538957b675 changed #asStevensonArceDitheredMonochromeImage
sr
parents: 5160
diff changeset
  5549
     (i asThresholdMonochromeImage:0.5) inspect
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5550
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5551
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5552
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5553
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5554
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5555
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5556
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5557
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5558
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5559
     i asStevensonArceDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5560
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5561
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5562
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5563
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5564
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5565
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5566
     i := Depth4Image
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  5567
             width:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  5568
             height:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  5569
             fromArray:#[
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  5570
                            16r01 16r23
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  5571
                            16r45 16r67
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  5572
                            16r89 16rab
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  5573
                            16rcd 16ref
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  5574
                        ].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5575
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5576
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5577
     i asStevensonArceDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5578
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5579
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5580
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5581
    "Created: 10.6.1996 / 12:38:29 / cg"
837
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  5582
    "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
  5583
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5584
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5585
asThresholdGrayFormOn:aDevice
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5586
    "return a thresholded grey form from the receiver image."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5587
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5588
    |depth|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5589
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5590
    (depth := aDevice depth) == 1 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5591
        ^ self asThresholdMonochromeFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5592
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5593
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5594
    ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5595
        makeDeviceGrayPixmapOn:aDevice
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5596
        depth:depth
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5597
        fromArray:(self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5598
                        orderedDitheredGrayBitsWithDitherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5599
                        ditherWidth:4
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5600
                        depth:depth)
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5601
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5602
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5603
     |i|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5604
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5605
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5606
     (i asThresholdGrayFormOn:Display) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5607
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5608
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5609
    "Created: 10.6.1996 / 18:38:31 / cg"
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  5610
    "Modified: 24.6.1997 / 22:19:46 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5611
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5612
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5613
asThresholdGrayImageDepth:depth
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5614
    "return a thresholded depth-x grey image from the receiver image."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5615
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  5616
    (depth == 1) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5617
        "/ for monochrome, there is highly specialized
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5618
        "/ monochrome dither code available
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5619
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5620
        ^ Depth1Image
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5621
            width:width
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5622
            height:height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5623
            fromArray:(
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5624
                self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5625
                    orderedDitheredMonochromeBitsWithDitherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5626
                    ditherWidth:4)
800
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  5627
    ].
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  5628
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5629
    ^ (self class implementorForDepth:depth)
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5630
        width:width
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5631
        height:height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5632
        fromArray:(
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5633
            self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5634
                orderedDitheredGrayBitsWithDitherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5635
                ditherWidth:4
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5636
                depth:depth)
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5637
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5638
    "
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5639
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5640
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5641
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5642
     (i asThresholdGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5643
     (i asThresholdGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5644
     (i asThresholdGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5645
     (i asThresholdGrayImageDepth:8) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5646
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5647
     (i asOrderedDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5648
     (i asOrderedDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5649
     (i asOrderedDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5650
     (i asOrderedDitheredGrayImageDepth:8) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5651
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5652
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5653
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5654
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5655
     (i asFloydSteinbergDitheredGrayImageDepth:8) inspect.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5656
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5657
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5658
    "Created: 7.6.1996 / 18:13:33 / cg"
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  5659
    "Modified: 24.6.1997 / 22:19:52 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5660
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5661
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5662
asThresholdMonochromeFormOn:aDevice
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5663
    "return a threshold monochrome form from the image."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5664
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5665
    ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5666
        asOrderedDitheredMonochromeFormOn:aDevice
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5667
        ditherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5668
        ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5669
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5670
    "
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5671
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5672
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5673
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5674
     i inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5675
     (i asThresholdMonochromeFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5676
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5677
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5678
     |i|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5679
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5680
     i := (Image fromFile:'goodies/bitmaps/a11.ico') magnifiedBy:10.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5681
     i inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5682
     (i asThresholdMonochromeFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5683
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5684
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5685
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5686
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5687
     i := Image fromFile:'goodies/bitmaps/granite.tiff'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5688
     i inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5689
     (i asThresholdMonochromeFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5690
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5691
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5692
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5693
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5694
     i := (Image fromFile:'goodies/bitmaps/PasteButton.tiff') magnifiedBy:10.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5695
     i inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5696
     (i asThresholdMonochromeFormOn:Display) inspect
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5697
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5698
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5699
    "Created: 7.6.1996 / 16:15:17 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5700
    "Modified: 10.6.1996 / 17:44:29 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5701
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5702
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5703
asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5704
    "return a threshold monochrome image from the image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5705
     Threshold means: brightness < 0.5 -> black / otherwise white"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5706
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5707
    ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5708
        asOrderedDitheredMonochromeImageWithDitherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5709
        ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5710
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5711
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5712
     |i i2|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5713
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5714
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5715
     i2 := i asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5716
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5717
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5718
     |i i2|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5719
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5720
     i := (Image fromFile:'/cdrom/icons/a/a11.ico') magnifiedBy:10.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5721
     i2 := i asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5722
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5723
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5724
     |i i2|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5725
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5726
     i := Image fromFile:'goodies/bitmaps/granite.tiff'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5727
     i2 := i asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5728
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5729
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5730
     |i i2|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5731
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5732
     i := (Image fromFile:'goodies/bitmaps/PasteButton.tiff') magnifiedBy:10.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5733
     i2 := i asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5734
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5735
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5736
    "Created: 7.6.1996 / 16:15:17 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5737
    "Modified: 7.6.1996 / 17:16:10 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5738
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5739
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5740
asThresholdMonochromeImage:thresholdBrighness
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5741
    "return a threshold monochrome image from the image.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5742
     The argument (0..1) gives the threshold value;
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5743
     Threshold means: brightness < threshold -> black / otherwise white"
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5744
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5745
    |value ditherMatrix|
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5746
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5747
    value := thresholdBrighness * 255.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5748
    ditherMatrix := ByteArray new:256 withAll:(value truncated).
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5749
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5750
    ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5751
        asOrderedDitheredMonochromeImageWithDitherMatrix:ditherMatrix
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5752
        ditherWidth:16
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5753
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5754
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5755
     |i|
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5756
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5757
     i := Image width:4 height:4 depth:4
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5758
                fromArray:#[ 16r01 16r23
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5759
                             16r45 16r67
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5760
                             16r89 16rab
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5761
                             16rcd 16ref ].
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5762
     i := i magnifiedBy:30.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5763
     i inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5764
     (i asThresholdMonochromeImage:0.125) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5765
     (i asThresholdMonochromeImage:0.25) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5766
     (i asThresholdMonochromeImage:0.5) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5767
     (i asThresholdMonochromeImage:0.75) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5768
     (i asThresholdMonochromeImage:1) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5769
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5770
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5771
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5772
     |i|
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5773
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5774
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5775
     i inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5776
     (i asThresholdMonochromeImage:0.125) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5777
     (i asThresholdMonochromeImage:0.25) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5778
     (i asThresholdMonochromeImage:0.5) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5779
     (i asThresholdMonochromeImage:0.625) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5780
     (i asThresholdMonochromeImage:0.75) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5781
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5782
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5783
    "Created: 7.6.1996 / 16:15:17 / cg"
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5784
    "Modified: 8.6.1996 / 14:51:57 / cg"
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5785
!
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5786
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5787
clearMaskedPixels
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5788
    "assuming that I already have a device representation
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5789
     in deviceForm, clear any masked pixels.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5790
     This will allow faster drawing in the future."
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5791
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5792
    maskedPixelsAre0 == true ifTrue:[^ self].   "/ already cleared
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5793
    mask isNil ifTrue:[^ self].         "/ no mask
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5794
    deviceForm isNil ifTrue:[^ self].   "/ no device rep.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5795
    mask depth ~~ 1 ifTrue:[^ self].    "/ not done with alpha masks
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5796
7494
70c399ea367b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7484
diff changeset
  5797
    deviceForm clearMaskedPixels:(mask asFormOn:device).
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5798
    maskedPixelsAre0 := true.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5799
6496
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  5800
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5801
    "Created: 12.4.1997 / 12:18:05 / cg"
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5802
    "Modified: 12.4.1997 / 12:20:19 / cg"
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5803
!
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5804
3104
edc88b280153 added #exactOn: - for Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3092
diff changeset
  5805
exactOn:aDevice
3107
ed51e2c00f1d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3105
diff changeset
  5806
    "for compatibility with color protocol - here, the same as #onDevice."
3104
edc88b280153 added #exactOn: - for Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3092
diff changeset
  5807
edc88b280153 added #exactOn: - for Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3092
diff changeset
  5808
    ^ self onDevice:aDevice
edc88b280153 added #exactOn: - for Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3092
diff changeset
  5809
!
edc88b280153 added #exactOn: - for Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3092
diff changeset
  5810
3105
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5811
exactOrNearestOn:aDevice
3107
ed51e2c00f1d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3105
diff changeset
  5812
    "for compatibility with color protocol - here, the same as #onDevice."
3105
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5813
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5814
    ^ self onDevice:aDevice
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5815
!
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5816
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5817
fromForm:aForm
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  5818
    "setup the receiver from a form"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5819
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5820
    |map c0 c1|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5821
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5822
    width := aForm width.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5823
    height := aForm height.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5824
    bitsPerSample := self bitsPerSample.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5825
    samplesPerPixel := self samplesPerPixel.
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5826
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5827
    aForm hasBits ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5828
        "/ must read the data from the device
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5829
        self from:aForm in:(0@0 extent:aForm extent).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5830
        ^ self
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5831
    ].
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5832
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5833
    "/ the form has all data available
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5834
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  5835
    self bits:(aForm bits).
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5836
    map := aForm colorMap.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5837
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5838
    aForm depth == 1 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5839
        map isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5840
            photometric := #whiteIs0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5841
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5842
            c0 := map at:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5843
            c1 := map at:2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5844
            ((c0 = Color white)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5845
            and:[c1 = Color black]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5846
                photometric := #whiteIs0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5847
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5848
                ((c0 = Color black)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5849
                and:[c1 = Color white]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5850
                    photometric := #blackIs0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5851
                ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5852
                    photometric := #palette.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5853
                    self setColorMap:(Array with:c0 with:c1).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5854
                ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5855
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5856
        ]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5857
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5858
        map notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5859
            photometric := #palette.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5860
            self setColorMap:(map copy).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5861
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5862
            "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5863
             photometric stays at default
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5864
             (which is rgb for d24, greyscale for others)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5865
            "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5866
        ]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5867
    ].
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  5868
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5869
    "Modified: 5.7.1996 / 16:24:31 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5870
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5871
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5872
fromImage:anImage
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5873
    "setup the receiver from another image.
4888
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5874
     Color precision may be lost, if conversion is from a higher depth image.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5875
     WARNING:
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5876
     This implementation is a slow fallback (the loop over the
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5877
     source pixels is very slow). If this method is used heavily, you
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5878
     may want to redefine it in concrete subclasses for common source images."
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5879
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5880
    ^ self fromImage:anImage photometric:nil
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5881
!
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5882
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5883
fromImage:anImage photometric:photometricOrNil
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5884
    "setup the receiver from another image and optionally set the photometric.
4888
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5885
     Color precision may be lost, if conversion is from a higher depth image.
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5886
     WARNING:
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5887
     This implementation is a slow fallback (the loop over the
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5888
     source pixels is very slow). If this method is used heavily, you
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5889
     may want to redefine it in concrete subclasses for common source images."
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5890
3363
de7e8628d329 fixed conversion of 3-3-2 8-bit truecolor images
Claus Gittinger <cg@exept.de>
parents: 3273
diff changeset
  5891
    |map clr mappedRowPixels samePhotometric
1784
25b96d8904c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1783
diff changeset
  5892
     h "{ Class: SmallInteger }"
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  5893
     w "{ Class: SmallInteger }" myDepth otherDepth|
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5894
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5895
    width := anImage width.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5896
    height := anImage height.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5897
    bitsPerSample := self bitsPerSample.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5898
    samplesPerPixel := self samplesPerPixel.
4859
553f9013f270 only try to fetch colormap for palette images
Claus Gittinger <cg@exept.de>
parents: 4858
diff changeset
  5899
4888
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5900
    photometricOrNil isNil ifTrue:[
7689
6ada06895459 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7688
diff changeset
  5901
        photometric := self class defaultPhotometric
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5902
        "/ photometric := anImage photometric
4888
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5903
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5904
        photometricOrNil == #rgba ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5905
            samplesPerPixel == 3 ifTrue:[ photometric := #rgb ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5906
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5907
            photometric := photometricOrNil
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5908
        ].
4888
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5909
    ].
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5910
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5911
    photometric == #palette ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5912
        self colormapFromImage:anImage photometric:photometric.
4859
553f9013f270 only try to fetch colormap for palette images
Claus Gittinger <cg@exept.de>
parents: 4858
diff changeset
  5913
    ].
1374
ab515c0576c6 preserve mask when creating an image from another image.
Claus Gittinger <cg@exept.de>
parents: 1362
diff changeset
  5914
    self mask:anImage mask.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5915
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  5916
    samePhotometric := photometric == anImage photometric.
7272
4ec4788352ce #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7271
diff changeset
  5917
    myDepth := self depth.
4ec4788352ce #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7271
diff changeset
  5918
    otherDepth := anImage depth.
4ec4788352ce #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7271
diff changeset
  5919
4ec4788352ce #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7271
diff changeset
  5920
    ((myDepth = otherDepth) and:[samePhotometric]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5921
        self bits:(anImage bits copy).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5922
        ^ self.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  5923
    ].
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  5924
7272
4ec4788352ce #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7271
diff changeset
  5925
    self bits:(ByteArray new: "uninitializedNew:"(self bytesPerRow * height)).
4ec4788352ce #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7271
diff changeset
  5926
4ec4788352ce #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7271
diff changeset
  5927
    myDepth >= otherDepth ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5928
        otherDepth <= 12 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5929
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5930
            "/ if my depth is greater, all colors can be represented,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5931
            "/ and the loop can be done over pixel values ...
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5932
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5933
            (colorMap isNil or:[samePhotometric not]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5934
                map := Array new:(1 bitShift:otherDepth).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5935
                1 to:map size do:[:i |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5936
                    clr := anImage colorFromValue:(i - 1).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5937
                    map at:i put:(self valueFromColor:clr).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5938
                ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5939
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5940
            mappedRowPixels := self pixelArraySpecies new:width.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5941
            h := height-1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5942
            w := width.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5943
            0 to:h do:[:row |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5944
                anImage rowAt:row into:mappedRowPixels startingAt:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5945
                map notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5946
                    1 to:w do:[:i |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5947
                        mappedRowPixels at:i put:(map at:(mappedRowPixels at:i)+1)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5948
                    ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5949
                ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5950
                self rowAt:row putAll:mappedRowPixels
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5951
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5952
            ^ self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5953
        ].
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5954
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5955
5712
b4d960599bc8 changed: #fromImage:photometric:
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  5956
    "/ a hack, for now - alpha is in the low-byte !!!!!!
7272
4ec4788352ce #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7271
diff changeset
  5957
    (myDepth == 24 and:[otherDepth == 32]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5958
        (samePhotometric and:[photometric == #rgb]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5959
            "/ can do the bits by simple stripping off the alpha channel
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5960
            self copyPixels32AlphaLowTo24From:anImage.
7272
4ec4788352ce #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7271
diff changeset
  5961
"/    anImage valuesFromX:0 y:0 toX:(width-1) y:(height-1) do:[:x :y :pixel |
4ec4788352ce #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7271
diff changeset
  5962
"/        |a r g b rgbPixel|
4ec4788352ce #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7271
diff changeset
  5963
"/
4ec4788352ce #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7271
diff changeset
  5964
"/        "/ bgra-pixel
4ec4788352ce #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7271
diff changeset
  5965
"/        "/ a := pixel bitAnd:16rFF.
4ec4788352ce #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7271
diff changeset
  5966
"/        r := (pixel bitShift:-8) bitAnd:16rFF.
4ec4788352ce #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7271
diff changeset
  5967
"/        g := (pixel bitShift:-16) bitAnd:16rFF.
4ec4788352ce #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7271
diff changeset
  5968
"/        b := (pixel bitShift:-24) bitAnd:16rFF.
4ec4788352ce #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7271
diff changeset
  5969
"/        rgbPixel := r + (g bitShift:8) + (b bitShift:16).
4ec4788352ce #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7271
diff changeset
  5970
"/        self pixelAtX:x y:y put:rgbPixel
4ec4788352ce #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7271
diff changeset
  5971
"/    ].
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5972
            ^ self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5973
        ].
5712
b4d960599bc8 changed: #fromImage:photometric:
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  5974
    ].
b4d960599bc8 changed: #fromImage:photometric:
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  5975
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5976
    anImage colorsFromX:0 y:0 toX:(width-1) y:(height-1) do:[:x :y :clr |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5977
        self colorAtX:x y:y put:clr
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5978
    ].
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5979
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5980
    "
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5981
     |i i2 i4 i8 i16 i24|
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5982
6496
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  5983
     i := GenericToolbarIconLibrary desktop32x32Icon2.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5984
     i inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5985
     i2 := Depth2Image fromImage:i.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5986
     i2 inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5987
     i4 := Depth4Image fromImage:i.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5988
     i4 inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5989
     i8 := Depth8Image fromImage:i.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5990
     i8 inspect.
6496
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  5991
     i16 := Depth16Image fromImage:i.
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  5992
     i16 inspect.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5993
     i24 := Depth24Image fromImage:i.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5994
     i24 inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5995
    "
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5996
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5997
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5998
     |i i24|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5999
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6000
     i := Image fromFile:'bitmaps/gifImages/garfield.gif' inPackage:'stx:goodies'.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6001
     Transcript showCR:(
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6002
        Time millisecondsToRun:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6003
            i24 := Depth24Image fromImage:i.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6004
        ]
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6005
     ).
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6006
     i24 inspect.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6007
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6008
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6009
     |i i24|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6010
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6011
     i := Image fromFile:'bitmaps/gifImages/garfield.gif' inPackage:'stx:goodies'.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6012
     MessageTally spyOn:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6013
        i24 := Depth24Image fromImage:i.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6014
     ]
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6015
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6016
7689
6ada06895459 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7688
diff changeset
  6017
    "Modified: / 22-11-2016 / 03:34:08 / cg"
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6018
    "Modified (format): / 30-01-2017 / 20:46:22 / stefan"
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  6019
!
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  6020
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  6021
fromSubImage:anImage in:aRectangle
7373
61933c223183 added metaData instVar (for free use by image reader)
Claus Gittinger <cg@exept.de>
parents: 7363
diff changeset
  6022
    "setup the receiver from another image, extracting a rectangular area.
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6023
     As with layouts, the rectangle may contain integers (= nr of pixels) or float numbers (= relative size).
7373
61933c223183 added metaData instVar (for free use by image reader)
Claus Gittinger <cg@exept.de>
parents: 7363
diff changeset
  6024
     Color precision may be lost, if conversion is from a higher depth image.
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6025
     For palette & rgb images, this may fail if a color cannot be represented."
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6026
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6027
    |w h xL yT imgWidth imgHeight|
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6028
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6029
    w := aRectangle width.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6030
    h := aRectangle height.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6031
    xL := aRectangle left.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6032
    yT := aRectangle top.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6033
    imgWidth := anImage width.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6034
    imgHeight := anImage height.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6035
7373
61933c223183 added metaData instVar (for free use by image reader)
Claus Gittinger <cg@exept.de>
parents: 7363
diff changeset
  6036
    xL isFloat ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6037
        xL := (imgWidth * xL) rounded min: imgWidth.
7373
61933c223183 added metaData instVar (for free use by image reader)
Claus Gittinger <cg@exept.de>
parents: 7363
diff changeset
  6038
    ].
61933c223183 added metaData instVar (for free use by image reader)
Claus Gittinger <cg@exept.de>
parents: 7363
diff changeset
  6039
    yT isFloat ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6040
        yT := (imgHeight * yT) rounded min:imgHeight.
7373
61933c223183 added metaData instVar (for free use by image reader)
Claus Gittinger <cg@exept.de>
parents: 7363
diff changeset
  6041
    ].
61933c223183 added metaData instVar (for free use by image reader)
Claus Gittinger <cg@exept.de>
parents: 7363
diff changeset
  6042
    w isFloat ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6043
        w := (imgWidth * w) rounded.
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6044
    ].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6045
    w := w min:(imgWidth - xL).
7373
61933c223183 added metaData instVar (for free use by image reader)
Claus Gittinger <cg@exept.de>
parents: 7363
diff changeset
  6046
    h isFloat ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6047
        h := (imgHeight * h) rounded.
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6048
    ].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6049
    h := h min:(imgHeight - yT).
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6050
    self fromSubImage:anImage inX:xL y:yT width:w height:h
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6051
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6052
    "
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6053
     |i i2 i4 i8 i16 i24|
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6054
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6055
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6056
     i inspect.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6057
     i4 := Depth4Image fromSubImage:i in:(300@160 corner:340@200).
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6058
     i4 inspect.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6059
     i8 := Depth8Image fromSubImage:i in:(300@160 corner:340@200).
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6060
     i8 inspect.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6061
     i24 := Depth24Image fromSubImage:i in:(300@160 corner:340@200).
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6062
     i24 inspect.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6063
    "
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6064
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6065
    "Created: / 20.9.1995 / 01:06:02 / claus"
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6066
    "Modified: / 20.9.1995 / 10:15:37 / claus"
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6067
    "Modified: / 18.5.1999 / 20:06:55 / cg"
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6068
!
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6069
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6070
fromSubImage:anImage inX:xL y:yT width:w height:h
7373
61933c223183 added metaData instVar (for free use by image reader)
Claus Gittinger <cg@exept.de>
parents: 7363
diff changeset
  6071
    "setup the receiver from another image, extracting a rectangular area.
61933c223183 added metaData instVar (for free use by image reader)
Claus Gittinger <cg@exept.de>
parents: 7363
diff changeset
  6072
     Color precision may be lost, if conversion is from a higher depth image.
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6073
     For palette & rgb images, this may fail if a color cannot be represented.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  6074
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  6075
     WARNING:
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  6076
       This implementation is a slow fallback (the loop over the
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  6077
       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
  6078
       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
  6079
       of creating a subImage with the same depth & palette."
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  6080
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6081
    |xR yB imagesMask maskClass|
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6082
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6083
    width := w.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6084
    height := h.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6085
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
  6086
    self createPixelStore.
3458
b2e098e6288b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3457
diff changeset
  6087
    depth := self depth.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  6088
    bitsPerSample := self bitsPerSample.
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
  6089
    "/ bitsPerPixel := self bitsPerPixel.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  6090
    samplesPerPixel := self samplesPerPixel.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  6091
    self colormapFromImage:anImage.
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  6092
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6093
    xR := xL + w - 1.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6094
    yB := yT + h - 1.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  6095
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  6096
    ((photometric == anImage photometric)
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  6097
    and:[self bitsPerPixel = anImage bitsPerPixel
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  6098
    and:[colorMap = anImage colorMap]]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6099
        "/ can do it by value
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6100
        anImage
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6101
            valuesFromX:xL y:yT toX:xR y:yB
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6102
            do:[:x :y :pixelValue | self pixelAtX:x-xL y:y-yT put:pixelValue ]
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  6103
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6104
        "/ must do it by colors
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6105
        anImage
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6106
            colorsFromX:xL y:yT toX:xR y:yB
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6107
            do:[:x :y :clr | self colorAtX:x-xL y:y-yT put:clr ]
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6108
    ].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6109
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6110
    (imagesMask := anImage mask) notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6111
        imagesMask depth == 1 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6112
            maskClass := ImageMask
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6113
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6114
            maskClass := imagesMask class.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6115
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6116
        mask := maskClass new fromSubImage:imagesMask inX:xL y:yT width:w height:h
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  6117
    ].
1963
ab2d96e4e140 care for masks in copy/copySubImage;
tz
parents: 1962
diff changeset
  6118
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  6119
    "
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  6120
     |i i2 i4 i8 i16 i24|
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  6121
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  6122
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  6123
     i inspect.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  6124
     i4 := Depth4Image fromSubImage:i in:(300@160 corner:340@200).
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  6125
     i4 inspect.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  6126
     i8 := Depth8Image fromSubImage:i in:(300@160 corner:340@200).
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  6127
     i8 inspect.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  6128
     i24 := Depth24Image fromSubImage:i in:(300@160 corner:340@200).
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  6129
     i24 inspect.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  6130
    "
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  6131
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  6132
    "Created: / 20.9.1995 / 01:06:02 / claus"
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  6133
    "Modified: / 20.9.1995 / 10:15:37 / claus"
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  6134
    "Modified: / 18.5.1999 / 20:06:55 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  6135
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  6136
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6137
monochromeOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6138
    "return a monochrome device image of the receiver for aDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6139
     (monochrome, even if device supports colors)"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6140
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6141
    ((aDevice == device) and:[monoDeviceForm notNil]) ifTrue:[^ self].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6142
    (device notNil and:[aDevice ~~ device]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6143
        "oops, I am already accociated to another device
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6144
         - need a copy ...
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6145
        "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6146
        ^ self copy monochromeOn:aDevice
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6147
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6148
    monoDeviceForm := self asMonochromeFormOn:aDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6149
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6150
3105
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  6151
nearestOn:aDevice
3107
ed51e2c00f1d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3105
diff changeset
  6152
    "for compatibility with color protocol - here, the same as #onDevice."
3105
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  6153
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  6154
    ^ self onDevice:aDevice
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  6155
!
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  6156
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6157
on:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6158
    "return an image with the same pixels as the receiver, but
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6159
     associated to aDevice. If the receiver is not yet bound to
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6160
     a device, this will be the receiver. Otherwise, a new image
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6161
     is returned."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6162
3623
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  6163
    "/ send out a warning: #on: is typically used to create views
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  6164
    "/ operating on a model.
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  6165
    "/ Please use #onDevice: to avoid confusion.
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  6166
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  6167
    <resource:#obsolete>
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  6168
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  6169
    self obsoleteMethodWarning:'use #onDevice:'.
3477
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6170
    ^ self onDevice:aDevice
1496
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  6171
!
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  6172
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  6173
onDevice:aDevice
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  6174
    "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
  6175
     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
  6176
     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
  6177
     is returned."
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  6178
2980
409e9547a45c ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  6179
    aDevice isNil ifTrue:[^ self].
3477
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6180
    ((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ self].
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6181
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6182
    (device notNil and:[aDevice ~~ device]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6183
        "oops, I am already associated to another device
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6184
         - need a copy ...
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6185
        "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6186
        ^ self copy onDevice:aDevice
3477
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6187
    ].
7573
656c59bc93ad #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7565
diff changeset
  6188
    device := aDevice.
3477
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6189
    deviceForm := self asFormOn:aDevice.
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6190
    maskedPixelsAre0 := nil.
6496
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  6191
    mask notNil ifTrue:[
7573
656c59bc93ad #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7565
diff changeset
  6192
        mask := mask onDevice:aDevice.
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6193
        self clearMaskedPixels.
6496
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  6194
    ].
3477
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6195
    Lobby register:self
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6196
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6197
    "Modified: / 22.8.1998 / 13:34:24 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6198
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6199
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6200
!Image methodsFor:'converting greyscale images'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6201
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6202
greyImageAsFormOn:aDevice
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6203
    "return a grey-deviceForm from the grey image."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6204
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  6205
    |pictureDepth nPlanes|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6206
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  6207
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6208
    nPlanes := samplesPerPixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6209
    (nPlanes == 2) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6210
        'Image [info]: alpha plane ignored' infoPrintCR.
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  6211
    ].
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  6212
    "/ first plane only
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6213
    pictureDepth := bitsPerSample at:1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6214
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6215
    "monochrome is very easy ..."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6216
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6217
    (pictureDepth == 1) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6218
        ^ Form width:width height:height fromArray:self bits onDevice:aDevice
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6219
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6220
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6221
    (aDevice visualType == #TrueColor) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6222
        ^ self greyImageAsTrueColorFormOn:aDevice
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6223
    ].
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6224
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6225
    "/ PseudoColor conversion also works for StaticColor,
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6226
    "/ GrayScale and DirectColor; although possibly with suboptimal results
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6227
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6228
    ^ self greyImageAsPseudoFormOn:aDevice
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6229
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6230
    "Modified: 19.10.1997 / 05:17:25 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6231
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6232
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6233
greyImageAsPseudoFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6234
    "return an 8-bit pseudo Form from the grey image"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6235
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6236
    |wideBits pictureDepth f map
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6237
     colorMap usedColors nUsed aColor
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6238
     nColors "{ Class: SmallInteger }"
1766
08b918d293a6 fixed conversion of greyScale images with colorCube
Claus Gittinger <cg@exept.de>
parents: 1764
diff changeset
  6239
     range id
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6240
     cube nR nG nB grayColors
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6241
     fit|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6242
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6243
    pictureDepth := bitsPerSample at:1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6244
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6245
    (#[2 4 8] includes:pictureDepth) ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6246
        self error:'currently only depth-2, 4 or 8 supported'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6247
        ^ nil
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6248
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6249
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6250
    wideBits := ByteArray uninitializedNew:(width * height).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6251
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6252
    (pictureDepth == 8) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6253
        "for 8bits, we scan for used colors first;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6254
         to avoid allocating too many colors"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6255
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6256
        (grayColors := aDevice fixGrayColors) notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6257
            DitherAlgorithm == #floydSteinberg ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6258
                f := self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6259
                       asFloydSteinbergDitheredDepth8FormOn:aDevice
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6260
                       colors:grayColors
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6261
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6262
            f notNil ifTrue:[^ f].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6263
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6264
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6265
        (cube := aDevice fixColors) notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6266
            nR := aDevice numFixRed.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6267
            nG := aDevice numFixGreen.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6268
            nB := aDevice numFixBlue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6269
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6270
            DitherAlgorithm == #floydSteinberg ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6271
                f := self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6272
                       asFloydSteinbergDitheredDepth8FormOn:aDevice
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6273
                       colors:cube
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6274
                       nRed:nR
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6275
                       nGreen:nG
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6276
                       nBlue:nB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6277
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6278
                f := self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6279
                       asNearestPaintDepth8FormOn:aDevice
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6280
                       colors:cube
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6281
                       nRed:nR
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6282
                       nGreen:nG
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6283
                       nBlue:nB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6284
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6285
            f notNil ifTrue:[^ f].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6286
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6287
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6288
        usedColors := self bits usedValues.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6289
        nUsed := usedColors max + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6290
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6291
        colorMap := Array new:nUsed.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6292
        range := 100 / 255.0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6293
        usedColors do:[:grey |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6294
            colorMap at:(grey + 1) put:(Color gray:(range * grey))
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6295
        ].
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  6296
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6297
        nColors := (1 bitShift:pictureDepth).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6298
        colorMap := Array new:nColors.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6299
        range := 100 / (nColors - 1) asFloat.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6300
        1 to:nColors do:[:i |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6301
            colorMap at:i put:(Color gray:(i - 1) * range).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6302
        ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6303
    ].
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6304
    photometric ~~ #blackIs0 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6305
        colorMap reverse
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6306
    ].
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6307
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6308
    "allocate those colors & setup the translation map"
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6309
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6310
    fit := true.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6311
    map := ByteArray uninitializedNew:256.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6312
    nColors := colorMap size.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6313
    1 to:nColors do:[:i |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6314
        aColor := colorMap at:i.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6315
        aColor notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6316
            aColor := aColor onDevice:aDevice.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6317
            colorMap at:i put:aColor.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6318
            id := aColor colorId.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6319
            id isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6320
                id := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6321
                fit := false.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6322
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6323
            map at:i put:id
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6324
        ]
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  6325
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6326
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6327
    fit ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6328
        "/ here comes the hard part - some grey value
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6329
        "/ could not be allocated.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6330
        "/ Must dither.
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6331
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6332
    ].
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6333
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6334
    "expand & translate"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6335
    self bits
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6336
        expandPixels:pictureDepth
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6337
        width:width height:height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6338
        into:wideBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6339
        mapping:map.
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  6340
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  6341
    f := Form width:width height:height depth:8 onDevice:aDevice.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6342
    f isNil ifTrue:[^ nil].
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6343
    f colorMap:colorMap.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6344
    aDevice
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6345
        drawBits:wideBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6346
        depth:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6347
        padding:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6348
        width:width height:height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6349
        x:0 y:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6350
        into:(f id)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6351
        x:0 y:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6352
        width:width height:height
7755
75f5eba88e77 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7689
diff changeset
  6353
        with:(f initGC).
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6354
    ^ f
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  6355
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6356
    "Modified: / 19-10-1997 / 05:19:44 / cg"
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6357
    "Modified: / 30-01-2017 / 19:37:01 / stefan"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6358
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  6359
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6360
greyImageAsTrueColorFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6361
    "return a true-color device-form for the grey-image receiver.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6362
     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
  6363
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  6364
    |myDepth    "{ Class: SmallInteger }"
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  6365
     nColors    "{ Class: SmallInteger }"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6366
     colorValues
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6367
     scaleDown
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  6368
     scaleRed   "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  6369
     scaleGreen "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  6370
     scaleBlue  "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  6371
     redShift   "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  6372
     blueShift  "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  6373
     greenShift "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6374
     form bestFormat usedDeviceDepth usedDeviceBitsPerPixel imageBits
1175
5595569cfbd3 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 1170
diff changeset
  6375
     greyValue  "{ Class: SmallInteger }"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6376
     h          "{ Class: SmallInteger }"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6377
     w          "{ Class: SmallInteger }"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6378
     pixelArray newPixelArray i|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6379
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6380
    "/ this is a slow fallback method; this ought to be
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6381
    "/ redefined in DepthxImage for more performance.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6382
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6383
    myDepth := self depth.
5315
cbac968cee6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5314
diff changeset
  6384
    myDepth > 16 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6385
        self error:'unsupported depth' mayProceed:true.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6386
        ^ nil
5315
cbac968cee6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5314
diff changeset
  6387
    ].
5314
517094dfa71c changed #greyImageAsTrueColorFormOn:
Claus Gittinger <cg@exept.de>
parents: 5313
diff changeset
  6388
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6389
    "/ compute scale to map from my pixels into devices range
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6390
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6391
    scaleDown := 1 bitShift:myDepth.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6392
    scaleRed := (1 bitShift:aDevice bitsRed).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6393
    scaleGreen := (1 bitShift:aDevice bitsGreen).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6394
    scaleBlue := (1 bitShift:aDevice bitsBlue).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6395
    redShift := aDevice shiftRed.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6396
    greenShift := aDevice shiftGreen.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6397
    blueShift := aDevice shiftBlue.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6398
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  6399
    "/ prepare the map
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  6400
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6401
    nColors := (1 bitShift:myDepth).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6402
    colorValues := Array new:nColors.
6256
1e510d7aea8e Inline block variable rename to avoid stc bug
Stefan Vogel <sv@exept.de>
parents: 6166
diff changeset
  6403
    1 to:nColors do:[:colorIdx |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6404
        |v gv bv rv nv|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6405
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6406
        "/ scale down to 0..1
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6407
        v := (colorIdx-1) / scaleDown.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6408
        rv := (v * scaleRed) truncated.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6409
        gv := (v * scaleGreen) truncated.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6410
        bv := (v * scaleBlue) truncated.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6411
        nv := rv bitShift:redShift.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6412
        nv := nv bitOr:(gv bitShift:greenShift).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6413
        nv := nv bitOr:(bv bitShift:blueShift).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6414
        colorValues at:colorIdx put:nv
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6415
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6416
    photometric == #whiteIs0 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6417
        "/ reverse the order; 0 is brightest
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6418
        colorValues reverse
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6419
    ].
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6420
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6421
    bestFormat := self bestSupportedImageFormatFor:aDevice.
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  6422
    usedDeviceDepth := bestFormat at:#depth.
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  6423
    usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6424
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6425
    "/ the temporary helper image is only needed to allow
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6426
    "/ the rowAt:putAll: calls below.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6427
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  6428
    i := (Image implementorForDepth:usedDeviceBitsPerPixel) new.
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  6429
    i width:width height:height.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
  6430
    i createPixelStore.
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
  6431
    imageBits := i bits.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6432
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6433
    "/ now, walk over the image and replace
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6434
    "/ colorMap indices by color values in the bits array
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6435
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6436
    h := height - 1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6437
    w := width - 1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6438
    pixelArray := self pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6439
    newPixelArray := i pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6440
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6441
    0 to:h do:[:y |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6442
        self rowAt:y into:pixelArray.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6443
        0 to:w do:[:x |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6444
            greyValue := pixelArray at:(x+1).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6445
            newPixelArray at:(x+1) put:(colorValues at:greyValue + 1).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6446
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6447
        i rowAt:y putAll:newPixelArray.
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  6448
    ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  6449
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  6450
    form := Form width:width height:height depth:usedDeviceDepth onDevice:aDevice.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6451
    form isNil ifTrue:[^ nil].
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6452
    form initGC.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6453
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6454
    form
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6455
        copyBitsFrom:imageBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6456
        bitsPerPixel:usedDeviceBitsPerPixel
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6457
        depth:usedDeviceDepth
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6458
        padding:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6459
        width:width height:height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6460
        x:0 y:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6461
        toX:0 y:0.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6462
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6463
    ^ form
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6464
5710
9928e8b52195 changed: #greyImageAsTrueColorFormOn:
Claus Gittinger <cg@exept.de>
parents: 5655
diff changeset
  6465
    "Created: / 20-10-1995 / 22:05:10 / cg"
9928e8b52195 changed: #greyImageAsTrueColorFormOn:
Claus Gittinger <cg@exept.de>
parents: 5655
diff changeset
  6466
    "Modified: / 05-02-2011 / 10:40:13 / cg"
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  6467
    "Modified (format): / 31-01-2017 / 14:42:05 / stefan"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6468
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
  6469
48194c26a46c Initial revision
claus
parents:
diff changeset
  6470
!Image methodsFor:'converting palette images'!
48194c26a46c Initial revision
claus
parents:
diff changeset
  6471
48194c26a46c Initial revision
claus
parents:
diff changeset
  6472
paletteImageAsFormOn:aDevice
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  6473
    "return a device-form for the palette-image receiver"
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  6474
380
c5ffc6d48a9e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 379
diff changeset
  6475
    |type ddepth|
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6476
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  6477
    ddepth := aDevice depth.
379
d74cdaa0adcb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
  6478
3940
b1b7dc76d7d7 not ifTrue -> ifFalse
Claus Gittinger <cg@exept.de>
parents: 3939
diff changeset
  6479
    aDevice hasGrayscales ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6480
        ^ self asMonochromeFormOn:aDevice
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  6481
    ].
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  6482
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6483
    type := aDevice visualType.
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6484
    (type == #StaticGray) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6485
        ddepth == 8 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6486
            ^ self paletteImageAsGray8FormOn:aDevice
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6487
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6488
        ^ self asGrayFormOn:aDevice
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6489
    ].
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  6490
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6491
    (type == #TrueColor) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6492
        DitherAlgorithm == #floydSteinberg ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6493
            ddepth == 8 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6494
                self depth == 8 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6495
                    "/ use fixColor dither algorithm
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6496
                    ^ self asDitheredTrueColor8FormOn:aDevice
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6497
                ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6498
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6499
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6500
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6501
        ^ self paletteImageAsTrueColorFormOn:aDevice
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6502
    ].
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6503
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6504
    "/ the PseudoColor conversion also works for
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6505
    "/ StaticColor, GrayScale & DirectColor; although possibly with suboptimal results
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6506
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6507
    ^ self paletteImageAsPseudoFormOn:aDevice
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6508
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6509
    "Modified: / 14-06-1996 / 19:31:01 / cg"
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6510
    "Modified: / 30-01-2017 / 20:55:32 / stefan"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6511
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  6512
48194c26a46c Initial revision
claus
parents:
diff changeset
  6513
paletteImageAsPseudoFormOn:aDevice
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  6514
    "return a pseudo-deviceForm from the palette image."
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6515
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  6516
    |tempImage d temp8|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  6517
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  6518
    d := self depth.
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6519
    (#[1 2 4 8] includes:d) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6520
        "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6521
         fallback code for some depth's:
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6522
         create a temporary Depth8Image and use its conversion method
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6523
        "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6524
        temp8 := ByteArray uninitializedNew:(width * height).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6525
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6526
        self bits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6527
            expandPixels:d
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6528
            width:width height:height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6529
            into:temp8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6530
            mapping:nil.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6531
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6532
        tempImage := Image width:width height:height depth:8 fromArray:temp8.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6533
        tempImage colorMap:colorMap.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6534
        ^ tempImage paletteImageAsPseudoFormOn:aDevice
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  6535
    ].
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  6536
    ^ self subclassResponsibility
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6537
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6538
    "Modified: / 30-01-2017 / 19:37:57 / stefan"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6539
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  6540
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6541
paletteImageAsTrueColorFormOn:aDevice
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6542
    "return a true-color device-form for the palette-image receiver."
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6543
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  6544
    |nColors "{ Class: SmallInteger }"
1605
64151392ff64 added generic #paletteImageAsTrueColorForm implementation
Claus Gittinger <cg@exept.de>
parents: 1595
diff changeset
  6545
     h       "{ Class: SmallInteger }"
64151392ff64 added generic #paletteImageAsTrueColorForm implementation
Claus Gittinger <cg@exept.de>
parents: 1595
diff changeset
  6546
     pixel   "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6547
     colorValues
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6548
     scaleRed scaleGreen scaleBlue redShift greenShift blueShift
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6549
     form imageBits bestFormat usedDeviceDepth usedDeviceBitsPerPixel
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6550
     i pixelArray newPixelArray
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6551
     clr r g b rv gv bv v "{ Class: SmallInteger }" |
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6552
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6553
    "/ this is a slow fallback method; this ought to be
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6554
    "/ redefined in DepthxImage for more performance.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6555
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6556
    bestFormat := self bestSupportedImageFormatFor:aDevice.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6557
    usedDeviceDepth := bestFormat at:#depth.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6558
    usedDeviceDepth == 1 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6559
        ^ self asMonochromeFormOn:aDevice.
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6560
    ].
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6561
    usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6562
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6563
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6564
    scaleRed := ((1 bitShift:aDevice bitsRed) - 1) / 255.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6565
    scaleGreen := ((1 bitShift:aDevice bitsGreen) - 1) / 255.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6566
    scaleBlue := ((1 bitShift:aDevice bitsBlue) - 1) / 255.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6567
    redShift := aDevice shiftRed.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6568
    greenShift := aDevice shiftGreen.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6569
    blueShift := aDevice shiftBlue.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6570
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6571
    nColors := colorMap size.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6572
    nColors <= 4096 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6573
        "/ precompute scales to map from 0..100 into devices range
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6574
        "/ (this may be different for the individual components)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6575
        colorValues := Array uninitializedNew:nColors.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6576
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6577
        1 to:nColors do:[:index |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6578
            r := colorMap redByteAt:index.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6579
            g := colorMap greenByteAt:index.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6580
            b := colorMap blueByteAt:index.
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6581
"/        clr := colorMap at:index.
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6582
            true "clr notNil" ifTrue:[
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6583
"/            r := clr red.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6584
"/            g := clr green.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6585
"/            b := clr blue.
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6586
                rv := (r * scaleRed) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6587
                gv := (g * scaleGreen) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6588
                bv := (b * scaleBlue) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6589
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6590
                v := rv bitShift:redShift.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6591
                v := v bitOr:(gv bitShift:greenShift).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6592
                v := v bitOr:(bv bitShift:blueShift).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6593
                colorValues at:index put:v.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6594
"/ clr print. ' ' print.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6595
"/ rv print. ' ' print. gv print. ' ' print. bv print. ' ' print.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6596
"/ ' -> ' print. v printNL.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6597
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6598
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6599
        ].
2864
dd151bfdff9d care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents: 2832
diff changeset
  6600
    ].
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6601
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6602
    "/ the temporary helper image is only needed to allow
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6603
    "/ the rowAt:putAll: calls below.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6604
1665
e0329f98904d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1664
diff changeset
  6605
    i := (Image implementorForDepth:usedDeviceBitsPerPixel) new.
e0329f98904d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1664
diff changeset
  6606
    i width:width height:height.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
  6607
    i createPixelStore.
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
  6608
    imageBits := i bits.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6609
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6610
    "/ now, walk over the image and replace
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6611
    "/ colorMap indices by color values in the bits array
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6612
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6613
    h := height - 1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6614
    pixelArray := self pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6615
    newPixelArray := i pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6616
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6617
    colorValues notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6618
        0 to:h do:[:y |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6619
            self rowAt:y into:pixelArray.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6620
            1 to:width do:[:x |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6621
                pixel := pixelArray at:x.
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  6622
                newPixelArray at:x put:(colorValues at:pixel + 1 ifAbsent:[0]).
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6623
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6624
            i rowAt:y putAll:newPixelArray.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6625
        ].
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6626
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6627
        0 to:h do:[:y |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6628
            self rowAt:y into:pixelArray.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6629
            1 to:width do:[:x |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6630
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6631
                pixel := pixelArray at:x.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6632
                clr := self colorFromValue:pixel.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6633
                r := clr redByte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6634
                g := clr greenByte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6635
                b := clr blueByte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6636
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6637
                rv := (r * scaleRed) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6638
                gv := (g * scaleGreen) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6639
                bv := (b * scaleBlue) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6640
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6641
                v := rv bitShift:redShift.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6642
                v := v bitOr:(gv bitShift:greenShift).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6643
                v := v bitOr:(bv bitShift:blueShift).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6644
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6645
                newPixelArray at:x put:v.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6646
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6647
            i rowAt:y putAll:newPixelArray.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6648
        ].
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  6649
    ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  6650
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  6651
    form := Form width:width height:height depth:usedDeviceDepth onDevice:aDevice.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6652
    form isNil ifTrue:[^ nil].
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6653
    form initGC.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6654
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6655
    form
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6656
        copyBitsFrom:imageBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6657
        bitsPerPixel:usedDeviceBitsPerPixel
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6658
        depth:usedDeviceDepth
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6659
        padding:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6660
        width:width height:height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6661
        x:0 y:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6662
        toX:0 y:0.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6663
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6664
    ^ form
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6665
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  6666
    "Modified: / 24-07-1998 / 00:56:14 / cg"
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  6667
    "Modified: / 31-01-2017 / 15:01:05 / stefan"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6668
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
  6669
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6670
!Image methodsFor:'converting rgb images'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6671
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6672
asDitheredTrueColor8FormOn:aDevice
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6673
    "convert an rgb image to a dithered depth8-form on aDevice.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6674
     Return the device-form.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  6675
     This method is only valid for trueColor displays."
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6676
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6677
    |fixColors pixel
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6678
     dstIdx     "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6679
     shiftRed   "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6680
     shiftGreen "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6681
     shiftBlue  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6682
     nRed    "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6683
     nGreen  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6684
     nBlue   "{ Class: SmallInteger }"|
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6685
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6686
    shiftRed := aDevice shiftRed.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6687
    shiftGreen := aDevice shiftGreen.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6688
    shiftBlue := aDevice shiftBlue.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6689
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6690
    nRed := 1 bitShift:aDevice bitsRed.
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6691
    nGreen := 1 bitShift:aDevice bitsGreen.
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6692
    nBlue := 1 bitShift:aDevice bitsBlue.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6693
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6694
    fixColors := Array new:(nRed * nGreen * nBlue).
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6695
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6696
    dstIdx := 1.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6697
    0 to:nRed - 1 do:[:sR |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6698
        0 to:nGreen - 1 do:[:sG |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6699
            0 to:nBlue - 1 do:[:sB |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6700
                pixel := (sR bitShift:shiftRed)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6701
                         + (sG bitShift:shiftGreen)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6702
                         + (sB bitShift:shiftBlue).
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6703
                fixColors at:dstIdx put:(Color colorId:pixel).
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6704
                dstIdx := dstIdx + 1
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6705
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6706
        ]
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6707
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6708
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6709
    ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6710
        asFloydSteinbergDitheredDepth8FormOn:aDevice
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6711
        colors:fixColors
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6712
        nRed:nRed nGreen:nGreen nBlue:nBlue
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  6713
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6714
    "Created: / 14-06-1996 / 17:23:52 / cg"
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6715
    "Modified: / 23-06-1997 / 15:22:36 / cg"
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6716
    "Modified (format): / 30-01-2017 / 19:06:08 / stefan"
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6717
!
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6718
5919
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6719
compressColorMap
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6720
    "calculates a new color map for the image, using only used colors"
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6721
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6722
    |depth newColorMap usedColors oldToNew oldBits newBits tmpBits sortBlockForColors|
5919
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6723
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6724
    depth := self depth.
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6725
    usedColors := self realUsedColors.
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6726
    sortBlockForColors := [:a :b |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6727
            a redByte == b redByte ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6728
                a greenByte == b greenByte ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6729
                    a blueByte < b blueByte
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6730
                ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6731
                    a greenByte < b greenByte
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6732
                ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6733
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6734
                a redByte < b redByte
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6735
            ]
5919
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6736
      ].
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6737
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6738
    "/ translation table
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6739
    oldToNew := ByteArray new:(1 bitShift:depth).
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6740
    newColorMap := usedColors asArray.
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6741
    newColorMap sort:sortBlockForColors.
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6742
    self colorMap notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6743
        self colorMap asArray keysAndValuesDo:[:oldIdx :clr |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6744
            |newPixel|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6745
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6746
            (usedColors includes:clr) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6747
                newPixel := newColorMap indexOf:clr.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6748
                oldToNew at:oldIdx put:newPixel-1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6749
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6750
        ].
5919
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6751
    ].
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6752
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6753
    oldBits := self bits.
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6754
    newBits := ByteArray new:(oldBits size).
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6755
    depth ~~ 8 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6756
        "/ expand/compress can only handle 8bits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6757
        tmpBits := ByteArray uninitializedNew:(self width*self height).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6758
        oldBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6759
            expandPixels:depth
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6760
            width:self width
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6761
            height:self height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6762
            into:tmpBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6763
            mapping:oldToNew.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6764
        tmpBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6765
            compressPixels:depth
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6766
            width:self width
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6767
            height:self height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6768
            into:newBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6769
            mapping:nil
5919
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6770
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6771
        oldBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6772
            expandPixels:depth
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6773
            width:self width
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6774
            height:self height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6775
            into:newBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6776
            mapping:oldToNew.
5919
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6777
    ].
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6778
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6779
    self bits:newBits.
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6780
    self colorMap:newColorMap.
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6781
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6782
    "Created: / 17-07-2012 / 12:13:18 / anwild"
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6783
!
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6784
7282
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6785
copyPixels32AlphaLowTo24From:anImage
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6786
    "tuned helper to copy pixels from a 32bit argb (alpha in low byte)
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6787
     to me as a 24bit non-alpha rgb image"
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6788
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6789
    |imageBits|
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6790
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6791
    imageBits := anImage bits.
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6792
%{
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6793
    OBJ _myBits = __INST(bytes);
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6794
    OBJ w = __INST(width);
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6795
    OBJ h = __INST(height);
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6796
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6797
    if (__isByteArrayLike(_myBits)
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6798
     && __isByteArrayLike(imageBits)
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6799
     && __bothSmallInteger(w, h)) {
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6800
        int _idx;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6801
        int _w = __intVal(w);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6802
        int _h = __intVal(h);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6803
        int _mySize = __byteArraySize(_myBits);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6804
        int _imgSize = __byteArraySize(imageBits);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6805
        char *_myBitsPtr = __ByteArrayInstPtr(_myBits)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6806
        char *_imgBitsPtr = __ByteArrayInstPtr(imageBits)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6807
        char *_myBitsEndPtr = _myBitsPtr + (_w * _h * 3);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6808
        char *_imgBitsEndPtr = _imgBitsPtr + (_w * _h * 4);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6809
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6810
        if ((_w * _h * 3) > _mySize) goto error;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6811
        if ((_w * _h * 4) > _imgSize) goto error;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6812
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6813
        while (_myBitsPtr < _myBitsEndPtr) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6814
            // fetch r,g,b skip a
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6815
            unsigned char _r = _imgBitsPtr[0];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6816
            unsigned char _g = _imgBitsPtr[1];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6817
            unsigned char _b = _imgBitsPtr[2];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6818
            _myBitsPtr[0] = _r;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6819
            _myBitsPtr[1] = _g;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6820
            _myBitsPtr[2] = _b;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6821
            _myBitsPtr += 3;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6822
            _imgBitsPtr += 4;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6823
        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6824
        RETURN( self );
7282
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6825
    }
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6826
error: ;
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6827
    console_printf("Image: oops - bits-size in copyPixels32\n");
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6828
%}.
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6829
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6830
    anImage valuesFromX:0 y:0 toX:(self width-1) y:(self height-1) do:[:x :y :pixel |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6831
        |a r g b rgbPixel|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6832
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6833
        "/ bgra-pixel
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6834
        "/ a := pixel bitAnd:16rFF.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6835
        r := (pixel bitShift:-8) bitAnd:16rFF.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6836
        g := (pixel bitShift:-16) bitAnd:16rFF.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6837
        b := (pixel bitShift:-24) bitAnd:16rFF.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6838
        rgbPixel := r + (g bitShift:8) + (b bitShift:16).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6839
        self pixelAtX:x y:y put:rgbPixel
7282
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6840
    ].
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6841
!
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6842
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6843
rgbImageAsFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6844
    "convert am rgb image to a device-form on aDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6845
     Return the device-form."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6846
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6847
    |visual|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6848
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6849
    visual := aDevice visualType.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6850
    (visual == #StaticGray) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6851
        ^ self asGrayFormOn:aDevice
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6852
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6853
    (visual == #TrueColor) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6854
        ^ self rgbImageAsTrueColorFormOn:aDevice
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6855
    ].
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6856
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6857
    "/ PseudoColor conversion also works for StaticColor, GrayScale
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6858
    "/ and DirectColor displays; although possibly with suboptimal results
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6859
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6860
    ^ self rgbImageAsPseudoFormOn:aDevice
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6861
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6862
    "Modified: 14.6.1996 / 19:30:06 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6863
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6864
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6865
rgbImageAsPseudoFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6866
    "return a pseudocolor form from the rgb-picture"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6867
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6868
    |n     "{ Class: SmallInteger }"
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6869
     depth "{ Class: SmallInteger }"
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6870
     palette f|
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6871
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6872
    (depth := self depth) <= 8 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6873
        "/ simulate it via a temporary palette image
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6874
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6875
        palette := Array new:(1 bitShift:depth).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6876
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6877
        n := (1 bitShift:depth)-1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6878
        0 to:n do:[:pixelValue |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6879
            palette at:(pixelValue+1) put:(self colorFromValue:pixelValue)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6880
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6881
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6882
        self setColorMap:palette.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6883
        photometric := #palette.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6884
        f := self paletteImageAsPseudoFormOn:aDevice.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6885
        self setColorMap:nil.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6886
        photometric := #rgb.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6887
        ^ f
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6888
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6889
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6890
    ^ self subclassResponsibility
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6891
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6892
    "Modified: 8.6.1996 / 10:58:25 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6893
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6894
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6895
rgbImageAsTrueColorFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6896
    "return a truecolor form from the rgb-picture."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6897
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  6898
    |bestFormat usedDeviceDepth usedDeviceBitsPerPixel
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6899
     form|
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6900
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6901
    bestFormat := self bestSupportedImageFormatFor:aDevice.
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  6902
    usedDeviceDepth := bestFormat at:#depth.
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  6903
    usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6904
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6905
    "/ 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
  6906
    usedDeviceBitsPerPixel == 15 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6907
        usedDeviceBitsPerPixel := 16
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  6908
    ].
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  6909
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6910
    "/
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6911
    "/ only the trivial case, where the depths match
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6912
    "/ is handled here; conversions are supposed to
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6913
    "/ be done in concrete subclasses (see D24Image)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6914
    "/
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6915
    self bitsPerPixel == usedDeviceBitsPerPixel ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6916
        "/ kludge - convert to a deep image first, then to a form.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6917
        ^ ((Image implementorForDepth:usedDeviceBitsPerPixel) fromImage:self) asFormOn:aDevice
5126
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  6918
"/        'Image [warning]: unimplemented trueColor depth in rgbImageAsTrueColorFormOn: ' errorPrint. self bitsPerPixel errorPrintCR.
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  6919
"/        ^ self asMonochromeFormOn:aDevice
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  6920
    ].
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  6921
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  6922
    form := Form width:width height:height depth:usedDeviceDepth onDevice:aDevice.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6923
    form isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6924
        'Image [warning]: display bitmap creation failed' errorPrintCR.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6925
        ^ nil
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6926
    ].
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6927
    form initGC.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6928
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6929
    form
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6930
        copyBitsFrom:self bits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6931
        bitsPerPixel:usedDeviceBitsPerPixel
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6932
        depth:usedDeviceDepth
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6933
        padding:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6934
        width:width height:height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6935
        x:0 y:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6936
        toX:0 y:0.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6937
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6938
    ^ form
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6939
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  6940
    "Modified: / 27-05-2007 / 13:44:26 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6941
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6942
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6943
!Image methodsFor:'copying'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6944
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6945
postCopy
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  6946
    "redefined to also copy the pixels and the colorMap
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  6947
     and clear out any device handles in the copy."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  6948
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6949
    bytes := bytes copy.
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6950
    colorMap isColormap ifTrue:[
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6951
        colorMap := colorMap copy.
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6952
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6953
        colorMap := MappedPalette withColors:colorMap.
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  6954
    ].
1963
ab2d96e4e140 care for masks in copy/copySubImage;
tz
parents: 1962
diff changeset
  6955
    device := deviceForm := monoDeviceForm := fullColorDeviceForm := nil.
ab2d96e4e140 care for masks in copy/copySubImage;
tz
parents: 1962
diff changeset
  6956
    mask := mask copy.
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  6957
    maskedPixelsAre0 := false.
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  6958
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6959
    "Modified: / 22-08-1998 / 11:27:09 / cg"
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6960
    "Modified: / 30-01-2017 / 19:16:02 / stefan"
2947
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6961
!
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6962
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6963
skipInstvarIndexInDeepCopy:index
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6964
    "a helper for deepCopy; only indices for which this method returns
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6965
     false are copied in a deep copy."
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6966
7494
70c399ea367b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7484
diff changeset
  6967
    "
70c399ea367b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7484
diff changeset
  6968
        self allInstanceVariableNames indexOf:#device
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  6969
        self allInstanceVariableNames indexOf:#deviceForm
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  6970
        self allInstanceVariableNames indexOf:#monoDeviceForm
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  6971
        self allInstanceVariableNames indexOf:#fullColorDeviceForm
7494
70c399ea367b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7484
diff changeset
  6972
    "
70c399ea367b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7484
diff changeset
  6973
70c399ea367b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7484
diff changeset
  6974
    index == 13 ifTrue:[
70c399ea367b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7484
diff changeset
  6975
        ^ true "/ skip device
70c399ea367b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7484
diff changeset
  6976
    ].
70c399ea367b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7484
diff changeset
  6977
    index == 14 ifTrue:[
70c399ea367b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7484
diff changeset
  6978
        ^ true "/ skip deviceForm
70c399ea367b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7484
diff changeset
  6979
    ].
70c399ea367b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7484
diff changeset
  6980
    index == 15 ifTrue:[
70c399ea367b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7484
diff changeset
  6981
        ^ true "/ skip monoDeviceForm
2947
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6982
    ].
7573
656c59bc93ad #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7565
diff changeset
  6983
    index == 16 ifTrue:[
656c59bc93ad #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7565
diff changeset
  6984
        ^ true "/ skip fullColorDeviceForm
656c59bc93ad #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7565
diff changeset
  6985
    ].
2947
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6986
    ^ false
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  6987
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  6988
    "Modified (comment): / 31-01-2017 / 15:41:40 / stefan"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6989
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6990
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6991
!Image methodsFor:'displaying'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6992
1737
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  6993
asImage
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  6994
    "ST-80 compatibility
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  6995
    "
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  6996
    ^ self
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  6997
!
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  6998
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6999
displayFilledOn:aGC
759
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  7000
    "display the receiver as an opaque image.
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  7001
     This allows Images to be wrapped by a FillingWrapper"
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  7002
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  7003
    aGC displayOpaqueForm:self x:0 y:0.
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  7004
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  7005
    "Created: 29.5.1996 / 10:34:18 / cg"
759
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  7006
    "Modified: 29.5.1996 / 10:52:36 / cg"
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  7007
!
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  7008
3865
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  7009
displayOn:aGC x:x y:y
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  7010
    "draw the receiver in the graphicsContext, aGC.
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  7011
     Smalltalk-80 compatibility"
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  7012
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  7013
    aGC displayForm:self x:x y:y.
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  7014
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  7015
    "Modified: 23.4.1996 / 11:12:31 / cg"
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  7016
    "Created: 12.5.1996 / 20:14:31 / cg"
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  7017
!
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  7018
3729
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  7019
displayOn:aGC x:x y:y opaque:opaque
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  7020
    "draw the receiver in the graphicsContext, aGC.
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  7021
     Smalltalk-80 compatibility"
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  7022
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  7023
    opaque ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7024
        self displayOpaqueOn:aGC x:x y:y .
3729
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  7025
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7026
        self displayOn:aGC x:x y:y .
3729
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  7027
    ].
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  7028
!
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  7029
3379
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  7030
displayOpaqueOn:aGC at:aPoint
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  7031
    "draw the receiver in the graphicsContext, aGC.
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  7032
     Smalltalk-80 compatibility"
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  7033
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  7034
    self displayOpaqueOn:aGC x:aPoint x y:aPoint y.
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  7035
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  7036
    "Modified: 12.5.1996 / 20:16:38 / cg"
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  7037
!
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  7038
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  7039
displayOpaqueOn:aGC x:x y:y
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  7040
    "draw the receiver in the graphicsContext, aGC.
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  7041
     Smalltalk-80 compatibility"
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  7042
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  7043
    aGC displayOpaqueForm:self x:x y:y.
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  7044
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  7045
    "Modified: 23.4.1996 / 11:12:31 / cg"
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  7046
    "Created: 22.10.1996 / 16:35:49 / cg"
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  7047
!
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  7048
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  7049
displayStrokedOn:aGC
759
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  7050
    "display the receiver as an non opaque image.
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  7051
     This allows Images to be wrapped by a StrokingWrapper"
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  7052
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  7053
    aGC displayForm:self x:0 y:0.
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  7054
759
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  7055
    "Created: 29.5.1996 / 10:34:18 / cg"
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  7056
    "Modified: 29.5.1996 / 10:52:30 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7057
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  7058
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7059
!Image methodsFor:'dither helpers'!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7060
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7061
burkesDitheredMonochromeBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7062
    "return the bitmap for a dithered monochrome bitmap from the image.
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  7063
     Works for any source depths / photometric.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  7064
     TODO: move to separate dither helper class"
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7065
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7066
    |dstIndex        "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7067
     nextDst         "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7068
     bytesPerMonoRow "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7069
     monoBits greyValues
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7070
     errorArray
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7071
     errorArray1
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7072
     e t
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7073
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7074
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7075
     bitCnt          "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7076
     byte            "{Class: SmallInteger }"
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  7077
     grey|
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7078
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7079
    self depth > 12 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7080
        ^ self floydSteinbergDitheredMonochromeBits
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7081
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7082
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7083
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7084
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7085
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7086
    bytesPerMonoRow := (w + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7087
    monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7088
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7089
    errorArray := Array new:(w+4).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7090
    errorArray1 := Array new:(w+4) withAll:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7091
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7092
    dstIndex := 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7093
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7094
    "/ 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
  7095
    "/ use table-value in loop
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7096
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7097
    greyValues := self greyMapForRange:(255*1024).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7098
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7099
    0 to:(h-1) do:[:y |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7100
        nextDst := dstIndex + bytesPerMonoRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7101
        byte := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7102
        bitCnt := 8.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7103
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7104
        t := errorArray.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7105
        errorArray := errorArray1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7106
        errorArray1 := t.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7107
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7108
        errorArray1 atAllPut:0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7109
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7110
        self valuesAtY:y from:0 to:(w-1) do:[:x :pixel |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7111
            |eP "{Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7112
             eD
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7113
             eI "{Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7114
             xE "{Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7115
             xN "{Class: SmallInteger }" |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7116
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7117
            "/ get the colors grey value [0 .. 1]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7118
            grey := greyValues at:(pixel + 1).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7119
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7120
            "/ adjust error
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7121
            xE := x + 2 + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7122
            grey := (grey + (errorArray at:xE)).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7123
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7124
            byte := byte bitShift:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7125
            grey > (127*1024) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7126
                byte := byte bitOr:1.      "/ white
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7127
                e := grey - (255*1024)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7128
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7129
                e := grey                  "/ black
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7130
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7131
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7132
            e ~= 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7133
                "/ distribute the error:
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7134
                "/                  XX  8  4
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7135
                "/             2  4  8  4  2
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7136
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7137
                eD := e.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7138
                eI := e // 32.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7139
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7140
                eP := eI * 8. eD := eD - eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7141
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7142
                xN := xE + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7143
                errorArray at:xN put:(errorArray at:xN) + eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7144
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7145
                eD := eD - eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7146
                errorArray1 at:xE put:(errorArray1 at:xE) + eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7147
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7148
                eP := eI * 4. eD := eD - eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7149
                xN := xE + 2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7150
                errorArray at:xN put:(errorArray at:xN) + eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7151
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7152
                eD := eD - eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7153
                xN := xE - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7154
                errorArray1 at:xN put:(errorArray1 at:xN) + eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7155
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7156
                eD := eD - eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7157
                xN := xE + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7158
                errorArray1 at:xN put:(errorArray1 at:xN) + eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7159
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7160
                eP := eI * 2. eD := eD - eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7161
                xN := xE - 2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7162
                errorArray1 at:xN put:(errorArray1 at:xN) + eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7163
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7164
                "/ eD := eD.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7165
                xN := xE + 2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7166
                errorArray1 at:xN put:(errorArray1 at:xN) + eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7167
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7168
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7169
            bitCnt := bitCnt - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7170
            bitCnt == 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7171
                monoBits at:dstIndex put:byte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7172
                dstIndex := dstIndex + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7173
                byte := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7174
                bitCnt := 8.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7175
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7176
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7177
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7178
        bitCnt ~~ 8 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7179
            byte := byte bitShift:bitCnt.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7180
            monoBits at:dstIndex put:byte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7181
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7182
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7183
        dstIndex := nextDst.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7184
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7185
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7186
    ^ monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7187
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7188
    "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
  7189
    "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
  7190
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7191
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  7192
floydSteinbergDitheredDepth8BitsColors:colors
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  7193
    "return a floyd-steinberg dithered bitmap from the receiver picture,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7194
     which must be a depth-8 image.
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  7195
     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
  7196
     (which need not be a colorCubes colors)."
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  7197
3157
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  7198
    ^ self floydSteinbergDitheredDepth8BitsColors:colors map:nil
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  7199
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  7200
!
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  7201
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  7202
floydSteinbergDitheredDepth8BitsColors:colors map:aMapOrNil
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7203
    "return a floyd-steinberg dithered bitmap from the receiver picture,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7204
     which must be a depth-24 image.
3157
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  7205
     This method expects an array of colors to be used for dithering
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  7206
     (which need not be a colorCubes colors)."
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  7207
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7208
    |pseudoBits
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7209
     ditherRGBBytes ditherColors
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7210
     w       "{Class: SmallInteger }"
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7211
     h       "{Class: SmallInteger }"
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7212
     index   "{Class: SmallInteger }"
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  7213
     lookupPos "{Class: SmallInteger }"
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7214
     ditherIds failed lastColor qScramble
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  7215
     clrLookup error clr|
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7216
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7217
    self depth ~~ 24 ifTrue:[^ nil].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7218
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7219
    "/ collect valid ditherColors ...
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7220
    aMapOrNil isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7221
        ditherColors := colors select:[:clr | clr notNil].
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7222
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7223
        ditherColors := colors
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7224
    ].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7225
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7226
    "/ ... and sort by manhatten distance from black
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7227
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7228
    qScramble := #(
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7229
                "/  2rX00X00X00X00
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7230
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7231
                    2r000000000000    "/ 0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7232
                    2r000000000100    "/ 1
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7233
                    2r000000100000    "/ 2
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7234
                    2r000000100100    "/ 3
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7235
                    2r000100000000    "/ 4
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7236
                    2r000100000100    "/ 5
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7237
                    2r000100100000    "/ 6
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7238
                    2r000100100100    "/ 7
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7239
                    2r100000000000    "/ 8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7240
                    2r100000000100    "/ 9
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7241
                    2r100000100000    "/ a
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7242
                    2r100000100100    "/ b
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7243
                    2r100100000000    "/ c
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7244
                    2r100100000100    "/ d
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7245
                    2r100100100000    "/ e
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7246
                    2r100100100100    "/ f
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7247
                  ).
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7248
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7249
    ditherColors := ditherColors sort:[:a :b |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7250
                                |cr "{Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7251
                                 cg "{Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7252
                                 cb "{Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7253
                                 i1 "{Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7254
                                 i2 "{Class: SmallInteger }"|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7255
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7256
                                cr := a redByte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7257
                                cg := a greenByte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7258
                                cb := a blueByte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7259
                                i1 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7260
                                i1 := i1 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7261
                                i1 := i1 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7262
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7263
                                cr := b redByte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7264
                                cg := b greenByte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7265
                                cb := b blueByte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7266
                                i2 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7267
                                i2 := i2 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7268
                                i2 := i2 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7269
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7270
                                i1 < i2
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7271
                    ].
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7272
    aMapOrNil isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7273
        ditherIds := (ditherColors asArray collect:[:clr | clr colorId]) asByteArray.
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7274
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7275
        ditherIds := aMapOrNil asByteArray
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7276
    ].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7277
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7278
    "/ build an index table, for fast lookup from manhatten-r-g-b distance
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7279
    "/ to the position in the colorList
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7280
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7281
    clrLookup := ByteArray new:(4096).
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7282
    index := 0.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7283
    ditherColors keysAndValuesDo:[:clrPosition :clr |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7284
        |r g b i|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7285
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7286
        r := clr redByte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7287
        g := clr greenByte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7288
        b := clr blueByte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7289
        i := qScramble at:((r bitShift:-4) bitAnd:16r0F) + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7290
        i := i + ((qScramble at:((g bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7291
        i := i + ((qScramble at:((b bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7292
        lookupPos := i.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7293
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  7294
        index+1 to:lookupPos do:[:idx|
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  7295
            clrLookup at:idx put:(clrPosition-1-1).
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  7296
        ].
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  7297
        index := lookupPos.
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7298
    ].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7299
    clrLookup from:index+1 to:4096 put:(ditherColors size - 1).
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7300
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7301
"/    [index <= (4095)] whileTrue:[
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7302
"/        clrLookup at:(index+1) put:(ditherColors size - 1).
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7303
"/        index := index + 1.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7304
"/    ].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7305
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7306
    "/ collect ditherColor components
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7307
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7308
    lastColor := ditherColors size.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7309
    ditherIds := ByteArray uninitializedNew:lastColor.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7310
    ditherRGBBytes := ByteArray uninitializedNew:(lastColor * 3).
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7311
    index := 1.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7312
    1 to:lastColor do:[:pix |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7313
        clr := ditherColors at:pix.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7314
        ditherRGBBytes at:index put:(clr redByte).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7315
        ditherRGBBytes at:index+1 put:(clr greenByte).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7316
        ditherRGBBytes at:index+2 put:(clr blueByte).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7317
        aMapOrNil isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7318
            ditherIds at:pix put:clr colorId.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7319
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7320
            ditherIds at:pix put:(aMapOrNil at:pix).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7321
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7322
        index := index + 3.
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7323
    ].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7324
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7325
    pseudoBits := ByteArray uninitializedNew:(width * height).
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7326
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7327
    w := width + 2.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7328
    error := ByteArray uninitializedNew:w*(3*2).
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7329
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7330
    w := width.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7331
    h := height.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7332
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7333
    failed := true.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7334
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7335
%{
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7336
    int __x, __y;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7337
    int __eR, __eG, __eB;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7338
    unsigned char *srcP, *dstP;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7339
    unsigned char *idP;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7340
    unsigned char *dp;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7341
    unsigned char *__clrLookup;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7342
    short *errP, *eP;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7343
    int __fR, __fG, __fB;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7344
    int iR, iG, iB;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7345
    int idx;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7346
    int __w = __intVal(w);
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7347
    int __h = __intVal(h);
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7348
    int __nColors = __intVal(lastColor);
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7349
    int __wR = -1, __wG, __wB;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7350
    static int __qScramble[16] = {
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7351
                    0x000 /* 2r000000000000    0 */,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7352
                    0x004 /* 2r000000000100    1 */,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7353
                    0x020 /* 2r000000100000    2 */,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7354
                    0x024 /* 2r000000100100    3 */,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7355
                    0x100 /* 2r000100000000    4 */,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7356
                    0x104 /* 2r000100000100    5 */,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7357
                    0x120 /* 2r000100100000    6 */,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7358
                    0x124 /* 2r000100100100    7 */,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7359
                    0x800 /* 2r100000000000    8 */,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7360
                    0x804 /* 2r100000000100    9 */,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7361
                    0x820 /* 2r100000100000    a */,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7362
                    0x824 /* 2r100000100100    b */,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7363
                    0x900 /* 2r100100000000    c */,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7364
                    0x904 /* 2r100100000100    d */,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7365
                    0x920 /* 2r100100100000    e */,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7366
                    0x924 /* 2r100100100100    f */,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7367
                  };
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7368
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7369
    if (__isByteArrayLike(__INST(bytes))
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7370
     && __isByteArray(pseudoBits)
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7371
     && __isByteArray(ditherRGBBytes)
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7372
     && __isByteArray(ditherIds)
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7373
     && __isByteArray(clrLookup)
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7374
     && __isByteArray(error)) {
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7375
        failed = false;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7376
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7377
        srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7378
        dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7379
        idP = __ByteArrayInstPtr(ditherIds)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7380
        __clrLookup = __ByteArrayInstPtr(clrLookup)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7381
        errP = (short *) __ByteArrayInstPtr(error)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7382
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7383
        /*
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7384
         * clear error accumulator
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7385
         */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7386
        eP = errP;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7387
        bzero(eP, (__w+2) * 2 * 3);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7388
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7389
        for (__y=__h; __y>0; __y--) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7390
            __eR = __eG = __eB = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7391
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7392
            eP = &(errP[3]);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7393
            __eR = eP[0];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7394
            __eG = eP[1];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7395
            __eB = eP[2];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7396
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7397
            for (__x=__w; __x>0; __x--) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7398
                int __want;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7399
                int pix;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7400
                int __wantR, __wantG, __wantB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7401
                int idx;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7402
                int tR, tG, tB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7403
                int nR, nG, nB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7404
                int dR, dG, dB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7405
                int minDelta, bestIdx;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7406
                int cnt;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7407
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7408
                __wantR = *srcP++;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7409
                __wantG = *srcP++;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7410
                __wantB = *srcP++;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7411
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7412
                /*
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7413
                 * wR, wG and wB is the wanted r/g/b value;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7414
                 */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7415
                __wantR = __wantR + __eR;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7416
                __wantG = __wantG + __eG;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7417
                __wantB = __wantB + __eB;
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7418
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7419
#define RED_SCALE 30
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7420
#define GREEN_SCALE 59
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7421
#define BLUE_SCALE 11
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7422
#define GOOD_DELTA 30
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7423
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7424
#define xRED_SCALE 1
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7425
#define xGREEN_SCALE 1
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7426
#define xBLUE_SCALE 1
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7427
#define xGOOD_DELTA 3
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7428
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7429
#define FAST_LOOKUP
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7430
/* #define ONE_SHOT */
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7431
#define NPROBE 8
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7432
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7433
#ifndef FAST_LOOKUP
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7434
                if ((__wantR == __wR)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7435
                 && (__wantG == __wG)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7436
                 && (__wantB == __wB)) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7437
                    /*
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7438
                     * same color again - reuse last bestMatch
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7439
                     */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7440
                } else
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7441
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7442
                {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7443
                    __wR = __wantR;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7444
                    __wG = __wantG;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7445
                    __wB = __wantB;
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7446
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7447
#ifdef FAST_LOOKUP
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7448
                    if(__wR > 255) __wR = 255;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7449
                    else if (__wR < 0) __wR = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7450
                    if(__wG > 255) __wG = 255;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7451
                    else if (__wG < 0) __wG = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7452
                    if(__wB > 255) __wB = 255;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7453
                    else if (__wB < 0) __wB = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7454
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7455
                    {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7456
                        int lookupIndex;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7457
                        int idx, idx0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7458
                        int d, delta;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7459
                        unsigned char *dp0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7460
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7461
                        dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7462
                        lookupIndex =    __qScramble[((__wR & 0xF0)>>4)];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7463
                        lookupIndex |=   __qScramble[((__wG & 0xF0)>>4)] >> 1;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7464
                        lookupIndex |=   __qScramble[((__wB & 0xF0)>>4)] >> 2;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7465
                        idx = bestIdx =__clrLookup[lookupIndex];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7466
                        dp += (idx+idx+idx);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7467
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7468
                        /* try color at lookupIndex */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7469
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7470
                        d = dp[0];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7471
                        delta = (__wR - d) * RED_SCALE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7472
                        if (delta < 0) delta = -delta;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7473
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7474
                        d = dp[1];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7475
                        if (__wG > d)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7476
                            delta += (__wG - d) * GREEN_SCALE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7477
                        else
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7478
                            delta += (d - __wG) * GREEN_SCALE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7479
                        d = dp[2];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7480
                        if (__wB > d)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7481
                            delta += (__wB - d) * BLUE_SCALE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7482
                        else
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7483
                            delta += (d - __wB) * BLUE_SCALE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7484
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7485
                        if (delta <= GOOD_DELTA) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7486
                            goto foundBest;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7487
                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7488
                        minDelta = delta;
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7489
# ifndef ONE_SHOT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7490
                        idx0 = idx; dp0 = dp;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7491
                        cnt = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7492
                        while ((++cnt <= NPROBE) && (idx > 0)) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7493
                            /* try previous color(s) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7494
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7495
                            idx--; dp -= 3;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7496
                            d = dp[0];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7497
                            delta = (__wR - d) * RED_SCALE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7498
                            if (delta < 0) delta = -delta;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7499
                            d = dp[1];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7500
                            if (__wG > d)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7501
                                delta += (__wG - d) * GREEN_SCALE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7502
                            else
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7503
                                delta += (d - __wG) * GREEN_SCALE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7504
                            d = dp[2];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7505
                            if (__wB > d)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7506
                                delta += (__wB - d) * BLUE_SCALE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7507
                            else
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7508
                                delta += (d - __wB) * BLUE_SCALE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7509
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7510
                            if (delta < minDelta) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7511
                                bestIdx = idx;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7512
                                if (delta <= GOOD_DELTA) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7513
                                    goto foundBest;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7514
                                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7515
                                minDelta = delta;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7516
                            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7517
                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7518
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7519
                        idx = idx0; dp = dp0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7520
                        cnt = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7521
                        while ((++cnt <= NPROBE) && (++idx < __nColors)) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7522
                            /* try next color */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7523
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7524
                            dp += 3;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7525
                            d = dp[0];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7526
                            delta = (__wR - d) * RED_SCALE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7527
                            if (delta < 0) delta = -delta;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7528
                            d = dp[1];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7529
                            if (__wG > d)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7530
                                delta += (__wG - d) * GREEN_SCALE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7531
                            else
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7532
                                delta += (d - __wG) * GREEN_SCALE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7533
                            d = dp[2];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7534
                            if (__wB > d)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7535
                                delta += (__wB - d) * BLUE_SCALE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7536
                            else
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7537
                                delta += (d - __wB) * BLUE_SCALE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7538
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7539
                            if (delta < minDelta) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7540
                                bestIdx = idx;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7541
                                if (delta <= GOOD_DELTA) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7542
                                    goto foundBest;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7543
                                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7544
                                minDelta = delta;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7545
                            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7546
                        }
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7547
# endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7548
                    }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7549
        foundBest: ;
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7550
#else
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7551
/*
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7552
                    if(__wR > 255) __wR = 255;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7553
                    else if (__wR < 0) __wR = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7554
                    if(__wG > 255) __wG = 255;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7555
                    else if (__wG < 0) __wG = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7556
                    if(__wB > 255) __wB = 255;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7557
                    else if (__wB < 0) __wB = 0;
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7558
*/
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7559
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7560
                    /* find the best matching color */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7561
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7562
                    minDelta = 99999;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7563
                    bestIdx = -1;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7564
                    dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7565
                    for (idx = 0; idx<__nColors; idx++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7566
                        int d, delta;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7567
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7568
                        d = dp[0];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7569
                        delta = (__wR - d) * RED_SCALE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7570
                        if (delta < 0) delta = -delta;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7571
                        if (delta < minDelta) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7572
                            d = dp[1];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7573
                            if (__wG > d)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7574
                                delta += (__wG - d) * GREEN_SCALE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7575
                            else
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7576
                                delta += (d - __wG) * GREEN_SCALE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7577
                            if (delta < minDelta) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7578
                                d = dp[2];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7579
                                if (__wB > d)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7580
                                    delta += (__wB - d) * BLUE_SCALE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7581
                                else
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7582
                                    delta += (d - __wB) * BLUE_SCALE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7583
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7584
                                if (delta < minDelta) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7585
                                    bestIdx = idx;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7586
                                    if (delta <= GOOD_DELTA) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7587
                                        break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7588
                                    }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7589
                                    minDelta = delta;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7590
                                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7591
                            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7592
                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7593
                        dp += 3;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7594
                    }
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7595
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7596
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7597
                dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7598
                dp += bestIdx * 3;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7599
                dR = dp[0];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7600
                dG = dp[1];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7601
                dB = dp[2];
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7602
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7603
/*
4725
c8896df7bd3f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4717
diff changeset
  7604
console_fprintf(stderr, "want: %d/%d/%d (%d/%d/%d) got: %d/%d/%d\n",
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7605
                __wantR, __wantG, __wantB,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7606
                __wR, __wG, __wB,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7607
                dR, dG, dB);
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7608
*/
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7609
                /*
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7610
                 * store the corresponding dither colors colorId
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7611
                 */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7612
                *dstP++ = idP[bestIdx];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7613
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7614
                /*
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7615
                 * the new error & distribute the error
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7616
                 */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7617
                __eR = __wantR - dR;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7618
                if (__eR) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7619
                    tR = __eR >> 4;  /* 16th of error */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7620
                    nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7621
                    eP[0] = tR*5;         /* 5/16th for (x / y+1) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7622
                    eP[-3] = tR*3;        /* 3/16th for (x-1 / y+1) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7623
                    eP[3] = __eR - (tR*15);  /* 1/16th for (x+1 / y+1) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7624
                    __eR = nR;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7625
                } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7626
                    __eR = eP[3];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7627
                    eP[0] = eP[-3] = eP[3] = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7628
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7629
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7630
                __eG = __wantG - dG;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7631
                if (__eG) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7632
                    tG = __eG >> 4;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7633
                    nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7634
                    eP[1] = tG*5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7635
                    eP[-2] = tG*3;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7636
                    eP[4] = __eG - (tG*15);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7637
                    __eG = nG;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7638
                } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7639
                    __eG = eP[4];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7640
                    eP[1] = eP[-2] = eP[4] = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7641
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7642
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7643
                __eB = __wantB - dB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7644
                if (__eB) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7645
                    tB = __eB >> 4;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7646
                    nB = eP[5] + (tB * 7);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7647
                    eP[2] = tB*5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7648
                    eP[-1] = tB*3;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7649
                    eP[5] = __eB - (tB*15);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7650
                    __eB = nB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7651
                } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7652
                    __eB = eP[5];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7653
                    eP[2] = eP[-1] = eP[5] = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7654
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7655
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7656
                eP += 3;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7657
            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7658
        }
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7659
    }
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7660
%}.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7661
    failed ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7662
        self primitiveFailed.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7663
        ^ nil
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7664
    ].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7665
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7666
    ^ pseudoBits
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  7667
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  7668
    "Modified: / 30-01-2017 / 19:58:45 / stefan"
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  7669
!
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  7670
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7671
floydSteinbergDitheredDepth8BitsColors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  7672
    "return a floyd-steinberg dithered bitmap from the receiver picture,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7673
     which must be a depth-8 image.
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  7674
     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
  7675
     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
  7676
     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
  7677
     colors assigned to aDevice, such as the preallocated colors of the
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7678
     Color class.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7679
     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
  7680
     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
  7681
     for example to create dithered Depth4Images from Depth8Images."
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7682
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7683
    |pseudoBits
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7684
     rgbBytes
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7685
     w       "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7686
     h       "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7687
     index   "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7688
     fixR    "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7689
     fixG    "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7690
     fixB    "{Class: SmallInteger }"
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7691
     fixGfixB
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7692
     fixIds failed map lastColor
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7693
     rgbIDX  "{Class: SmallInteger }"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7694
     idxAndErrRBytes idxAndErrGBytes idxAndErrBBytes
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7695
     error clr|
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7696
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  7697
    self depth ~~ 8 ifTrue:[^ nil].
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  7698
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7699
    fixR := nRed.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7700
    fixR == 0 ifTrue:[ ^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7701
    fixG := nGreen.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7702
    fixG == 0 ifTrue:[ ^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7703
    fixB := nBlue.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7704
    fixB == 0 ifTrue:[ ^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7705
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7706
    "/ simple check
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7707
    (fixR * fixG * fixB) ~~ fixColors size ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7708
        self error:'invalid color array passed'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7709
        ^ nil
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7710
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7711
    fixIds := (fixColors asArray collect:[:clr | clr colorId]) asByteArray.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7712
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7713
    "/
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7714
    "/ collect color components as integer values (for integer arithmetic)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7715
    "/
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7716
    rgbBytes := ByteArray uninitializedNew:256 * 3.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7717
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7718
    index := 1.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7719
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7720
    photometric == #palette ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7721
        lastColor := colorMap size - 1
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7722
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7723
        lastColor := 255.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7724
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7725
    0 to:lastColor do:[:pix |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7726
        clr := self colorFromValue:pix.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7727
        rgbBytes at:index put:(clr redByte).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7728
        rgbBytes at:index+1 put:(clr greenByte).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7729
        rgbBytes at:index+2 put:(clr blueByte).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7730
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7731
        index := index + 3.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7732
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7733
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7734
    pseudoBits := ByteArray uninitializedNew:(width * height).
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7735
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7736
    w := width + 2.
1636
c30f6644666e dont use bcopy in #floydSteinbergDitheredDepth8BitsColors
Claus Gittinger <cg@exept.de>
parents: 1630
diff changeset
  7737
    error := ByteArray new:w*(3*2).
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7738
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7739
    w := width.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7740
    h := height.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7741
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7742
    idxAndErrRBytes := ByteArray uninitializedNew:256*2.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7743
    idxAndErrGBytes := ByteArray uninitializedNew:256*2.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7744
    idxAndErrBBytes := ByteArray uninitializedNew:256*2.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7745
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7746
    fixGfixB := fixG * fixB.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7747
    index := 1.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7748
    0 to:255 do:[:i |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7749
        rgbIDX := (i * (fixR-1) + 128) // 255. "red index rounded"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7750
        idxAndErrRBytes at:index put:(rgbIDX * fixGfixB).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7751
        idxAndErrRBytes at:index+1 put:i - (rgbIDX * 255 // (fixR-1)) + 128.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7752
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7753
        rgbIDX := (i * (fixG-1) + 128) // 255. "green index rounded"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7754
        idxAndErrGBytes at:index put:(rgbIDX * fixB).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7755
        idxAndErrGBytes at:index+1 put:i - (rgbIDX * 255 // (fixG-1)) + 128.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7756
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7757
        rgbIDX := (i * (fixB-1) + 128) // 255. "blue index rounded"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7758
        idxAndErrBBytes at:index put:(rgbIDX ).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7759
        idxAndErrBBytes at:index+1 put:i - (rgbIDX * 255 // (fixB-1)) + 128.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7760
        index := index + 2.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7761
    ].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7762
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7763
    failed := true.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7764
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7765
%{
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7766
    int __x, __y;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7767
    int __eR, __eG, __eB;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7768
    unsigned char *srcP, *dstP;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7769
    unsigned char *rgbP;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7770
    unsigned char *idP;
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7771
    unsigned char *__idxAndErrRBytes, *__idxAndErrGBytes, *__idxAndErrBBytes;
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7772
    short *errP, *eP;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7773
    int idx;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7774
    int __w = __intVal(w);
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7775
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7776
    if (__isByteArrayLike(__INST(bytes))
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7777
     && __isByteArray(pseudoBits)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7778
     && __isByteArray(rgbBytes)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7779
     && __isByteArray(fixIds)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7780
     && __isByteArray(error)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7781
     && __bothSmallInteger(fixR, fixG)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7782
     && __isSmallInteger(fixB)) {
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7783
        failed = false;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7784
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7785
        srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7786
        dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7787
        rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7788
        idP = __ByteArrayInstPtr(fixIds)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7789
        __idxAndErrRBytes = __ByteArrayInstPtr(idxAndErrRBytes)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7790
        __idxAndErrGBytes = __ByteArrayInstPtr(idxAndErrGBytes)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7791
        __idxAndErrBBytes = __ByteArrayInstPtr(idxAndErrBBytes)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7792
        errP = (short *) __ByteArrayInstPtr(error)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7793
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7794
        eP = errP;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7795
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7796
        for (__y=__intVal(h); __y>0; __y--) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7797
            __eR = __eG = __eB = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7798
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7799
            eP = &(errP[3]);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7800
            __eR = eP[0];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7801
            __eG = eP[1];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7802
            __eB = eP[2];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7803
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7804
            for (__x=__w; __x>0; __x--) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7805
                int __want;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7806
                int pix;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7807
                int idx;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7808
                int tR, tG, tB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7809
                int nR, nG, nB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7810
                int iRGB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7811
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7812
                pix = *srcP++;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7813
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7814
                /*
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7815
                 * wR, wG and wB is the wanted r/g/b value;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7816
                 */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7817
                pix = pix+pix+pix;  /* pix * 3 */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7818
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7819
                /*
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7820
                 * compute indexR/G/B and the new error:
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7821
                 */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7822
                __want = rgbP[pix]   + __eR;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7823
                if (__want > 255) __want = 255;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7824
                else if (__want < 0) __want = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7825
                __want += __want;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7826
                idx = __idxAndErrRBytes[__want];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7827
                __eR = __idxAndErrRBytes[__want+1];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7828
                __eR -= 128;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7829
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7830
                __want = rgbP[pix+1] + __eG;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7831
                if (__want > 255) __want = 255;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7832
                else if (__want < 0) __want = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7833
                __want += __want;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7834
                idx += __idxAndErrGBytes[__want];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7835
                __eG = __idxAndErrGBytes[__want+1];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7836
                __eG -= 128;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7837
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7838
                __want = rgbP[pix+2] + __eB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7839
                if (__want > 255) __want = 255;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7840
                else if (__want < 0) __want = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7841
                __want += __want;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7842
                idx += __idxAndErrBBytes[__want];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7843
                __eB = __idxAndErrBBytes[__want+1];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7844
                __eB -= 128;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7845
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7846
                /*
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7847
                 * store the corresponding dither colors colorId
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7848
                 */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7849
                *dstP++ = idP[idx];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7850
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7851
                /*
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7852
                 * distribute the error
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7853
                 */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7854
                if (__eR) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7855
                    tR = __eR >> 4;  /* 16th of error */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7856
                    nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7857
                    eP[0] = tR*5;         /* 5/16th for (x / y+1) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7858
                    eP[-3] = tR*3;        /* 3/16th for (x-1 / y+1) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7859
                    eP[3] = __eR - (tR*15);  /* 1/16th for (x+1 / y+1) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7860
                    __eR = nR;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7861
                } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7862
                    __eR = eP[3];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7863
                    eP[0] = eP[-3] = eP[3] = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7864
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7865
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7866
                if (__eG) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7867
                    tG = __eG >> 4;  /* 16th of error */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7868
                    nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7869
                    eP[1] = tG*5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7870
                    eP[-2] = tG*3;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7871
                    eP[4] = __eG - (tG*15);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7872
                    __eG = nG;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7873
                } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7874
                    __eG = eP[4];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7875
                    eP[1] = eP[-2] = eP[4] = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7876
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7877
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7878
                if (__eB) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7879
                    tB = __eB >> 4;  /* 16th of error */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7880
                    nB = eP[5] + (tB * 7);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7881
                    eP[2] = tB*5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7882
                    eP[-1] = tB*3;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7883
                    eP[5] = __eB - (tB*15);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7884
                    __eB = nB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7885
                } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7886
                    __eB = eP[5];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7887
                    eP[2] = eP[-1] = eP[5] = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7888
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7889
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7890
                eP += 3;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7891
            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7892
        }
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7893
    }
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7894
%}.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7895
    failed ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7896
        self primitiveFailed.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7897
        ^ nil
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7898
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7899
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7900
    ^ pseudoBits
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7901
!
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7902
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7903
floydSteinbergDitheredGrayBitsDepth:depth
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7904
    "return the bits for dithering a gray image from the image.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7905
     Works for any source depths / photometric,
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7906
     but possibly slow since each pixel is processed individually.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7907
     Redefined by some subclasses for more performance (D8Image/D24Image)"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7908
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7909
    |dstIndex        "{Class: SmallInteger }"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7910
     nextDst         "{Class: SmallInteger }"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7911
     bytesPerOutRow  "{Class: SmallInteger }"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7912
     outBits greyValues greyErrors greyPixels greyLevels
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7913
     errorArray
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7914
     nextErrorArray
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7915
     t
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7916
     w               "{Class: SmallInteger }"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7917
     h               "{Class: SmallInteger }"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7918
     bitCnt          "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7919
     byte            "{Class: SmallInteger }"
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7920
     grey
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7921
     eR eRB eB eLB |
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7922
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7923
    depth > 8 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7924
        self error:'unimplemented conversion'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7925
        ^ nil
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7926
    ].
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7927
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7928
    w := width.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7929
    h := height.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7930
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7931
    bytesPerOutRow := ((w * depth) + 7) // 8.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7932
    outBits := ByteArray uninitializedNew:(bytesPerOutRow * h).
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7933
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7934
    greyLevels := (1 bitShift:depth) - 1.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7935
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7936
    errorArray := Array new:w+2.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7937
    nextErrorArray := Array new:w+2.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7938
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7939
    nextErrorArray atAllPut:0.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7940
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7941
    dstIndex := 1.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7942
    bitCnt := 8.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7943
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7944
    self depth <= 12 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7945
        "/ fetch scaled brightness values outside of loop into a table;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7946
        "/ use table-value in loop
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7947
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7948
        greyValues := self greyMapForRange:(greyLevels).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7949
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7950
        greyPixels := greyValues collect:[:v | v isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7951
                                                   0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7952
                                               ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7953
                                                   v truncated]].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7954
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7955
        greyPixels := ByteArray withAll:greyPixels.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7956
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7957
        greyErrors := greyValues collect:[:v | v isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7958
                                                   0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7959
                                               ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7960
                                                   ((v - v truncated) * 1024) truncated
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7961
                                               ]].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7962
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7963
        0 to:(h-1) do:[:y |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7964
            nextDst := dstIndex + bytesPerOutRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7965
            byte := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7966
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7967
            t := errorArray.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7968
            errorArray := nextErrorArray.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7969
            nextErrorArray := t.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7970
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7971
            nextErrorArray atAllPut:0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7972
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7973
            self valuesAtY:y from:0 to:(w-1) do:[:x :value |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7974
                |e     "{ Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7975
                 pixel "{ Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7976
                 error "{ Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7977
                 e16   "{ Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7978
                 xE    "{ Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7979
                 xN    "{ Class: SmallInteger }" |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7980
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7981
                pixel := greyPixels at:(value + 1).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7982
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7983
                "/ adjust error
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7984
                xE := x + 2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7985
                error := (greyErrors at:(value + 1)) + (errorArray at:xE).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7986
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7987
                byte := byte bitShift:depth.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7988
                error > 512 "0.5" ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7989
                    pixel := pixel + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7990
                    e := error - 1024 "1.0"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7991
                ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7992
                    e := error
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7993
                ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7994
                byte := byte bitOr:pixel.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7995
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7996
                e ~= 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7997
                    e16 := e // 16.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7998
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7999
                    eR  := e16 * 7.              "/ 7/16 to right
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8000
                    eRB := e16 "* 1".            "/ 1/16 to right below
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8001
                    eB  := e16 * 5.              "/ 5/16 to below
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8002
                    eLB := e - eR - eRB - eB.  "/ 3/16 to left below
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8003
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8004
                    xN := xE + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8005
                    eR ~= 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8006
                        errorArray     at:xN put:(errorArray at:xN) + eR.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8007
                    ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8008
                    eRB ~= 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8009
                        nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8010
                    ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8011
                    eB ~= 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8012
                        nextErrorArray at:xE put:(nextErrorArray at:xE) + eB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8013
                    ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8014
                    eLB ~= 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8015
                        xN := xE - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8016
                        nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8017
                    ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8018
                ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8019
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8020
                bitCnt := bitCnt - depth.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8021
                bitCnt == 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8022
                    outBits at:dstIndex put:byte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8023
                    dstIndex := dstIndex + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8024
                    byte := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8025
                    bitCnt := 8.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8026
                ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8027
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8028
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8029
            bitCnt ~~ 8 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8030
                byte := byte bitShift:bitCnt.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8031
                outBits at:dstIndex put:byte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8032
                bitCnt := 8.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8033
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8034
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8035
            dstIndex := nextDst.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8036
        ].
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8037
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8038
        0 to:(h-1) do:[:y |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8039
            nextDst := dstIndex + bytesPerOutRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8040
            byte := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8041
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8042
            t := errorArray.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8043
            errorArray := nextErrorArray.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8044
            nextErrorArray := t.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8045
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8046
            nextErrorArray atAllPut:0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8047
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8048
            self colorsAtY:y from:0 to:(w-1) do:[:x :clr |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8049
                |e     "{ Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8050
                 pixel "{ Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8051
                 error "{ Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8052
                 e16   "{ Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8053
                 xE    "{ Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8054
                 xN    "{ Class: SmallInteger }" |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8055
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8056
                grey := (clr brightness * greyLevels).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8057
                pixel := grey truncated.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8058
                error := ((grey - pixel) * 1024) truncated.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8059
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8060
                "/ adjust error
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8061
                xE := x + 2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8062
                error := error + (errorArray at:xE).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8063
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8064
                byte := byte bitShift:depth.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8065
                error > 512 "0.5" ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8066
                    pixel := pixel + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8067
                    e := error - 1024 "1.0"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8068
                ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8069
                    e := error
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8070
                ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8071
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8072
                byte := byte bitOr:pixel.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8073
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8074
                e ~= 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8075
                    e16 := e // 16.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8076
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8077
                    eR  := e16 * 7.              "/ 7/16 to right
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8078
                    eRB := e16 "* 1".            "/ 1/16 to right below
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8079
                    eB  := e16 * 5.              "/ 5/16 to below
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8080
                    eLB := e - eR - eRB - eB.  "/ 3/16 to left below
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8081
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8082
                    xN := xE + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8083
                    eR ~= 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8084
                        errorArray     at:xN put:(errorArray at:xN) + eR.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8085
                    ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8086
                    eRB ~= 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8087
                        nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8088
                    ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8089
                    eB ~= 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8090
                        nextErrorArray at:xE put:(nextErrorArray at:xE) + eB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8091
                    ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8092
                    eLB ~= 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8093
                        xN := xE - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8094
                        nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8095
                    ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8096
                ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8097
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8098
                bitCnt := bitCnt - depth.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8099
                bitCnt == 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8100
                    outBits at:dstIndex put:byte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8101
                    dstIndex := dstIndex + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8102
                    byte := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8103
                    bitCnt := 8.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8104
                ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8105
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8106
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8107
            bitCnt ~~ 8 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8108
                byte := byte bitShift:bitCnt.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8109
                outBits at:dstIndex put:byte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8110
                bitCnt := 8.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8111
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8112
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8113
            dstIndex := nextDst.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8114
        ].
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8115
    ].
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8116
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8117
    ^ outBits
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8118
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8119
    "Created: 10.6.1996 / 13:28:22 / cg"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8120
    "Modified: 11.6.1996 / 00:13:38 / cg"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8121
!
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8122
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8123
floydSteinbergDitheredMonochromeBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8124
    "return the bitmap for a dithered monochrome bitmap from the image.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8125
     Works for any source depths / photometric,
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8126
     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
  8127
     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
  8128
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8129
    |dstIndex        "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8130
     nextDst         "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8131
     bytesPerMonoRow "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8132
     monoBits greyValues
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8133
     errorArray
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8134
     nextErrorArray
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8135
     e eD t
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8136
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8137
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8138
     bitCnt          "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8139
     byte            "{Class: SmallInteger }"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8140
     grey
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8141
     eR eRB eB eLB |
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8142
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8143
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8144
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8145
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8146
    bytesPerMonoRow := (w + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8147
    monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8148
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8149
    errorArray := Array new:w+2.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8150
    nextErrorArray := Array new:w+2.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8151
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8152
    nextErrorArray atAllPut:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8153
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8154
    dstIndex := 1.
828
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8155
    bitCnt := 8.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8156
    byte := 0.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8157
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8158
    self depth <= 12 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8159
        "/ fetch scaled brightness values outside of loop into a table;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8160
        "/ use table-value in loop
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8161
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8162
        greyValues := self greyMapForRange:(255 * 1024).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8163
        greyValues := greyValues collect:[:v | v rounded].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8164
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8165
        0 to:(h-1) do:[:y |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8166
            nextDst := dstIndex + bytesPerMonoRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8167
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8168
            t := errorArray.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8169
            errorArray := nextErrorArray.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8170
            nextErrorArray := t.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8171
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8172
            nextErrorArray atAllPut:0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8173
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8174
            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
  8175
%{
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8176
                int __grey, __e;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8177
                int __byte = __intVal(byte);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8178
                OBJ *__errorArray = __ArrayInstPtr(errorArray)->a_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8179
                OBJ *__nextErrorArray = __ArrayInstPtr(nextErrorArray)->a_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8180
                int __x = __intVal(x);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8181
                int __eR, __eB, __eRB, __eLB, __eI;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8182
                int __bitCnt = __intVal(bitCnt);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8183
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8184
                __grey = __intVal(__ArrayInstPtr(greyValues)->a_element[__intVal(pixel)]);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8185
                __grey += __intVal(__errorArray[__x+1]);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8186
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8187
                __byte <<= 1;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8188
                if (__grey > 127*1024) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8189
                    __e = __grey - (255*1024);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8190
                    __byte |= 1;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8191
                } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8192
                    __e = __grey;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8193
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8194
                if (__e) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8195
                    __eI = __e >> 4;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8196
                    __eR  = __eI * 7;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8197
                    __eRB = __eI * 1;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8198
                    __eB  = __eI * 5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8199
                    __eLB = __e - __eR - __eRB - __eB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8200
                    __errorArray[__x+2] = __MKSMALLINT(__intVal(__errorArray[__x+2]) + __eR);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8201
                    __nextErrorArray[__x+2] = __MKSMALLINT(__intVal(__nextErrorArray[__x+2]) + __eRB);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8202
                    __nextErrorArray[__x+1] = __MKSMALLINT(__intVal(__nextErrorArray[__x+1]) + __eB);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8203
                    __nextErrorArray[__x  ] = __MKSMALLINT(__intVal(__nextErrorArray[__x  ]) + __eLB);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8204
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8205
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8206
                __bitCnt--;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8207
                if (__bitCnt == 0) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8208
                    int __dstIndex = __intVal(dstIndex);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8209
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8210
                    __ByteArrayInstPtr(monoBits)->ba_element[__dstIndex-1] = __byte;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8211
                    dstIndex = __MKSMALLINT(__dstIndex + 1);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8212
                    __byte = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8213
                    __bitCnt = 8;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8214
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8215
                byte = __MKSMALLINT(__byte);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8216
                bitCnt = __MKSMALLINT(__bitCnt);
828
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8217
%}.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8218
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8219
"/                |eI "{ Class: SmallInteger }"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8220
"/                 xE "{ Class: SmallInteger }"
829
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  8221
"/                 xN "{ Class: SmallInteger }" |
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  8222
"/
828
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8223
"/                "/ get the colors grey value [0 .. 1]
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8224
"/                grey := greyValues at:(pixel + 1).
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8225
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8226
"/                "/ adjust error
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8227
"/                xE := x + 2.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8228
"/                grey := (grey + (errorArray at:xE)).
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8229
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8230
"/                byte := byte bitShift:1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8231
"/                grey > (127*1024) ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8232
"/                    byte := byte bitOr:1.      "/ white
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8233
"/                    e := grey - (255*1024)
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8234
"/                ] ifFalse:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8235
"/                    e := grey                  "/ black
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8236
"/                ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8237
"/                e ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8238
"/                    eD := e.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8239
"/                    eI := e // 16.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8240
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8241
"/                    eR  := eI * 7.              "/ 7/16 to right
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8242
"/                    eRB := eI * 1.              "/ 1/16 to right below
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8243
"/                    eB  := eI * 5.              "/ 5/16 to below
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8244
"/                    eLB := eD - eR - eRB - eB.  "/ 3/16 to left below
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8245
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8246
"/                    xN := xE + 1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8247
"/                    eR ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8248
"/                        errorArray     at:xN put:(errorArray at:xN) + eR.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8249
"/                    ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8250
"/                    eRB ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8251
"/                        nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8252
"/                    ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8253
"/                    eB ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8254
"/                        nextErrorArray at:xE put:(nextErrorArray at:xE) + eB.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8255
"/                    ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8256
"/                    eLB ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8257
"/                        xN := xE - 1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8258
"/                        nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8259
"/                    ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8260
"/                ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8261
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8262
"/                bitCnt := bitCnt - 1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8263
"/                bitCnt == 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8264
"/                    monoBits at:dstIndex put:byte.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8265
"/                    dstIndex := dstIndex + 1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8266
"/                    byte := 0.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8267
"/                    bitCnt := 8.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8268
"/                ].
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8269
                  0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8270
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8271
            bitCnt ~~ 8 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8272
                byte := byte bitShift:bitCnt.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8273
                monoBits at:dstIndex put:byte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8274
                bitCnt := 8.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8275
                byte := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8276
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8277
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8278
            dstIndex := nextDst.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8279
        ].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8280
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8281
        'Image [info]: slow floydSteinberg dither ..' infoPrintCR.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8282
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8283
        0 to:(h-1) do:[:y |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8284
            nextDst := dstIndex + bytesPerMonoRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8285
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8286
            t := errorArray.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8287
            errorArray := nextErrorArray.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8288
            nextErrorArray := t.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8289
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8290
            nextErrorArray atAllPut:0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8291
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8292
            self colorsAtY:y from:0 to:(w-1) do:[:x :clr |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8293
                |eI "{ Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8294
                 xE "{ Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8295
                 xN "{ Class: SmallInteger }" |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8296
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8297
                "/ get the colors grey value [0 .. 1]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8298
                grey := (clr brightness * 255).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8299
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8300
                "/ adjust error
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8301
                xE := x + 2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8302
                grey := (grey + (errorArray at:xE)) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8303
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8304
                byte := byte bitShift:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8305
                grey > 127 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8306
                    byte := byte bitOr:1.      "/ white
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8307
                    e := grey - 255
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8308
                ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8309
                    e := grey                  "/ black
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8310
                ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8311
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8312
                e ~= 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8313
                    eD := e.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8314
                    eI := e // 16.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8315
                    eR  := eI * 7.              "/ 7/16 to right
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8316
                    eRB := eI "* 1".            "/ 1/16 to right below
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8317
                    eB  := eI * 5.              "/ 5/16 to below
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8318
                    eLB := eD - eR - eRB - eB.  "/ 3/16 to left below
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8319
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8320
                    xN := xE + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8321
                    eR ~= 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8322
                        errorArray     at:xN put:(errorArray at:xN) + eR.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8323
                    ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8324
                    eRB ~= 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8325
                        nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8326
                    ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8327
                    eB ~= 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8328
                        nextErrorArray at:xE put:(nextErrorArray at:xE) + eB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8329
                    ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8330
                    eLB ~= 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8331
                        xN := xE - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8332
                        nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8333
                    ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8334
                ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8335
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8336
                bitCnt := bitCnt - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8337
                bitCnt == 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8338
                    monoBits at:dstIndex put:byte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8339
                    dstIndex := dstIndex + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8340
                    byte := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8341
                    bitCnt := 8.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8342
                ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8343
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8344
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8345
            bitCnt ~~ 8 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8346
                byte := byte bitShift:bitCnt.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8347
                monoBits at:dstIndex put:byte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8348
                bitCnt := 8.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8349
                byte := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8350
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8351
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8352
            dstIndex := nextDst.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8353
        ].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8354
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8355
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8356
    ^ monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8357
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8358
    "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
  8359
    "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
  8360
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8361
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8362
nearestPaintDepth8BitsColors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8363
    "return a nearest paint bitmap from the receiver picture,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8364
     which must be a depth-8 image.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8365
     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
  8366
     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
  8367
     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
  8368
     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
  8369
     Color class."
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8370
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8371
    |pseudoBits
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8372
     fixR    "{Class: SmallInteger }"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8373
     fixG    "{Class: SmallInteger }"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8374
     fixB    "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8375
     fixGfixB
884
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  8376
     r       "{Class: SmallInteger }"
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  8377
     g       "{Class: SmallInteger }"
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  8378
     b       "{Class: SmallInteger }"
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  8379
     idx     "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8380
     idMap lastColor
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8381
     clr|
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8382
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8383
    self depth ~~ 8 ifTrue:[^ nil].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8384
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8385
    photometric == #palette ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8386
        lastColor := colorMap size - 1
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8387
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8388
        lastColor := 255.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8389
    ].
884
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  8390
    idMap := ByteArray uninitializedNew:256.
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  8391
3915
dd2dae91c068 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3914
diff changeset
  8392
    (nRed isNil or:[nGreen isNil or:[nBlue isNil]]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8393
        0 to:lastColor do:[:pix |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8394
            |clr repClr|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8395
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8396
            clr := self colorFromValue:pix.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8397
            repClr := clr nearestIn:fixColors.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8398
            idMap at:(pix+1) put:(fixColors identityIndexOf:repClr)-1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8399
        ].
3914
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  8400
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8401
        fixR := nRed.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8402
        fixR == 0 ifTrue:[ ^ nil].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8403
        fixG := nGreen.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8404
        fixG == 0 ifTrue:[ ^ nil].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8405
        fixB := nBlue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8406
        fixB == 0 ifTrue:[ ^ nil].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8407
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8408
        "/ simple check
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8409
        (fixR * fixG * fixB) ~~ fixColors size ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8410
            self error:'invalid color array passed'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8411
            ^ nil
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8412
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8413
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8414
        "/
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8415
        "/ collect colorIds
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8416
        "/
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8417
        fixGfixB := fixG * fixB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8418
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8419
        0 to:lastColor do:[:pix |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8420
            clr := self colorFromValue:pix.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8421
            r := clr redByte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8422
            g := clr greenByte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8423
            b := clr blueByte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8424
            idx := ((r * (fixR-1) + 128) // 255) * fixGfixB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8425
            idx := idx + (((g * (fixG-1) + 128) // 255) * fixB).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8426
            idx := idx + ((b * (fixB-1) + 128) // 255).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8427
            idMap at:(pix+1) put:(fixColors at:(idx+1)) colorId.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8428
        ].
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8429
    ].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8430
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8431
    pseudoBits := ByteArray uninitializedNew:(width * height).
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8432
884
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  8433
    "/ translate
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  8434
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  8435
    self bits
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8436
        expandPixels:8         "xlate only"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8437
        width:width height:height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8438
        into:pseudoBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8439
        mapping:idMap.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8440
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8441
    ^ pseudoBits
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8442
884
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  8443
    "Modified: 18.6.1996 / 09:18:09 / cg"
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8444
!
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8445
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8446
nfloydSteinbergDitheredDepth8BitsColors:colors
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8447
    "return a floyd-steinberg dithered bitmap from the receiver picture,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8448
     which must be a depth-8 image.
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8449
     This method expects an array of colors to be used for dithering
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8450
     (which need not be a colorCubes colors)."
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8451
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8452
    |pseudoBits
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8453
     rgbBytes
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8454
     ditherRGBBytes ditherColors
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8455
     w       "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8456
     h       "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8457
     index   "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8458
     numR    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8459
     numG    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8460
     numB    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8461
     bitsR    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8462
     bitsG    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8463
     bitsB    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8464
     maxBits  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8465
     maskR    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8466
     maskG    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8467
     maskB    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8468
     shR      "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8469
     shG      "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8470
     shB      "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8471
     ditherIds failed map lastColor colorsByDistance qScramble
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8472
     clrLookup lookupPos cube nCube
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8473
     dR  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8474
     dG  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8475
     dB  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8476
     iR    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8477
     iRG   "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8478
     iRGB  "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8479
     clr
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8480
     rI  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8481
     gI  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8482
     bI  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8483
     maxIDX  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8484
     subCubeColorCollection
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8485
     error
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8486
     dl "{Class: SmallInteger }"|
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8487
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8488
    self depth ~~ 8 ifTrue:[^ nil].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8489
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8490
    "/
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8491
    "/ collect color components as integer values (for integer arithmetic)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8492
    "/
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8493
    rgbBytes := ByteArray uninitializedNew:256 * 3.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8494
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8495
    photometric == #palette ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8496
        lastColor := colorMap size - 1
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8497
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8498
        lastColor := 255.
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8499
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8500
    index := 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8501
    0 to:lastColor do:[:pix |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8502
        clr := self colorFromValue:pix.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8503
        rgbBytes at:index put:(clr redByte).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8504
        rgbBytes at:index+1 put:(clr greenByte).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8505
        rgbBytes at:index+2 put:(clr blueByte).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8506
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8507
        index := index + 3.
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8508
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8509
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8510
    "/ collect valid ditherColors ...
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8511
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8512
    ditherColors := colors select:[:clr | clr notNil].
1845
6860bd2c4684 care to not use invalid ditherColors in nfloyd*
Claus Gittinger <cg@exept.de>
parents: 1815
diff changeset
  8513
    ditherColors := ditherColors select:[:clr | clr colorId notNil].
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8514
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8515
    "/ collect ditherColor components
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8516
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8517
    lastColor := ditherColors size.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8518
    ditherIds := ByteArray uninitializedNew:lastColor.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8519
    ditherRGBBytes := ByteArray uninitializedNew:(lastColor * 3).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8520
    index := 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8521
    1 to:lastColor do:[:pix |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8522
        clr := ditherColors at:pix.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8523
        ditherRGBBytes at:index put:(clr redByte).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8524
        ditherRGBBytes at:index+1 put:(clr greenByte).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8525
        ditherRGBBytes at:index+2 put:(clr blueByte).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8526
        ditherIds at:pix put:clr colorId.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8527
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8528
        index := index + 3.
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8529
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8530
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8531
    "/ place the ditherColor positions into a color cube
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8532
    bitsR := 5.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8533
    bitsG := 6.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8534
    bitsB := 4.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8535
    maxBits := 6.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8536
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8537
"/    bitsR := 4.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8538
"/    bitsG := 4.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8539
"/    bitsB := 3.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8540
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8541
    numR := 1 bitShift:bitsR.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8542
    numG := 1 bitShift:bitsG.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8543
    numB := 1 bitShift:bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8544
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8545
    maskR := (numR-1) bitShift:(bitsG + bitsB).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8546
    maskG := (numG-1) bitShift:bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8547
    maskB := numB-1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8548
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8549
    shR := -16+bitsR+bitsG+bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8550
    shG := -16+bitsG+bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8551
    shB := -16+bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8552
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8553
    maxIDX := numR*numG*numB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8554
    cube := Array new:maxIDX.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8555
    1 to:lastColor do:[:clrIdx |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8556
        clr := ditherColors at:clrIdx.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8557
        rI := clr scaledRed. rI := (rI bitShift:shR) bitAnd:maskR.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8558
        gI := clr scaledGreen. gI := (gI bitShift:shG) bitAnd:maskG.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8559
        bI := clr scaledBlue. bI := (bI bitShift:shB) bitAnd:maskB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8560
        index := rI + gI + bI + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8561
        subCubeColorCollection := cube at:index.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8562
        subCubeColorCollection isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8563
            subCubeColorCollection := OrderedCollection new.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8564
            cube at:index put:subCubeColorCollection.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8565
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8566
        subCubeColorCollection add:(clrIdx - 1).
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8567
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8568
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8569
    shR := 1 bitShift:(bitsG+bitsB).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8570
    shG := 1 bitShift:(bitsB).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8571
    shB := 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8572
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8573
    1 to:maxIDX do:[:i |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8574
        subCubeColorCollection := cube at:i.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8575
        subCubeColorCollection notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8576
            cube at:i put:(subCubeColorCollection asByteArray)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8577
        ]
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8578
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8579
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8580
"/    nCube := cube copy.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8581
"/
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8582
"/    cube keysAndValuesDo:[:i :indices |
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8583
"/        indices notNil ifTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8584
"/            nCube at:i put:(indices asByteArray)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8585
"/        ] ifFalse:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8586
"/            "/ find nearest color
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8587
"/
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8588
"/            dl := 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8589
"/            [dl < maxBits] whileTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8590
"/                dR := dl negated.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8591
"/                [dR <= dl] whileTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8592
"/                    iR := i + (dR * shR).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8593
"/                    (iR > 0 and:[iR < maxIDX]) ifTrue:[
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8594
"/                        dG := dl negated.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8595
"/                        [dG < dl] whileTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8596
"/                            iRG := iR + (dG * shG).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8597
"/                            (iRG > 0 and:[iRG < maxIDX]) ifTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8598
"/                                dB := dl negated.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8599
"/                                [dB < dl] whileTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8600
"/                                    iRGB := iRG + dB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8601
"/                                    (iRG > 0 and:[iRG < maxIDX]) ifTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8602
"/                                        (cube at:iRGB) notNil ifTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8603
"/                                            nCube at:i put:(cube at:iRGB).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8604
"/                                            dB := dG := dR := dl := 999.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8605
"/                                        ]
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8606
"/                                    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8607
"/                                    dB := dB + 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8608
"/                                ]
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8609
"/                            ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8610
"/                            dG := dG + 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8611
"/                        ]
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8612
"/                    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8613
"/                    dR := dR + 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8614
"/                ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8615
"/                dl := dl + 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8616
"/            ]
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8617
"/        ]
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8618
"/    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8619
"/self halt.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8620
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8621
    "/ now, cube contains collections of colors which are
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8622
    "/ positioned in a subCube; quickly accessed by a lookup
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8623
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8624
    pseudoBits := ByteArray uninitializedNew:(width * height).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8625
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8626
    w := width.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8627
    h := height.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8628
    error := ByteArray new:(w+2)*3*2.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8629
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8630
%{
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8631
#define BITSR   5
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8632
#define BITSG   6
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8633
#define BITSB   4
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8634
#define MAXBITS 6
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8635
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8636
#define xBITSR   4
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8637
#define xBITSG   4
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8638
#define xBITSB   3
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8639
#define xMAXBITS 4
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8640
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8641
#define NR      32 /* (1<<BITSR) */
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8642
#define NG      64 /* (1<<BITSG) */
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8643
#define NB      16 /* (1<<BITSB) */
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8644
#define MAXRGB  64 /* (1<<MAXBITS) */
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8645
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8646
#define SHR     (BITSG+BITSB)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8647
#define SHG     BITSB
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8648
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8649
#define REMEMBER_SEARCH
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8650
#define xNO_FLOYD_STEINBERG
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8651
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8652
    int __x, __y;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8653
    int __eR, __eG, __eB;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8654
    unsigned char *srcP, *dstP;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8655
    unsigned char *rgbP;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8656
    unsigned char *idP;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8657
    short *errP, *eP;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8658
    int __fR, __fG, __fB;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8659
    int idx;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8660
    int __w = __intVal(w);
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8661
    int __h = __intVal(h);
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8662
    int __nColors = __intVal(lastColor);
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8663
    int __wR = -1, __wG, __wB;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8664
    OBJ *__cube;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8665
    int cubeIndex, cubeIndex2;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8666
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8667
    if (__isByteArrayLike(__INST(bytes))
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8668
     && __isByteArray(pseudoBits)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8669
     && __isByteArray(rgbBytes)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8670
     && __isByteArray(ditherRGBBytes)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8671
     && __isByteArray(ditherIds)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8672
     && __isByteArray(error)) {
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8673
        failed = false;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8674
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8675
        srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8676
        dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8677
        rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8678
        idP = __ByteArrayInstPtr(ditherIds)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8679
        errP = (short *) __ByteArrayInstPtr(error)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8680
        __cube = __ArrayInstPtr(cube)->a_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8681
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8682
        eP = errP;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8683
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8684
        for (__y=__h; __y>0; __y--) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8685
            eP = &(errP[3]);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8686
            __eR = eP[0];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8687
            __eG = eP[1];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8688
            __eB = eP[2];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8689
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8690
            for (__x=__w; __x>0; __x--) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8691
                int __want;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8692
                int pix;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8693
                int __wantR, __wantG, __wantB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8694
                int idx;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8695
                int tR, tG, tB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8696
                int nR, nG, nB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8697
                int __dR, __dG, __dB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8698
                int minDelta, bestIdx;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8699
                int __iR, __iG, __iB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8700
                int cR, cG, cB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8701
                int delta;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8702
                OBJ subCubeColors;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8703
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8704
                pix = *srcP++;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8705
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8706
                /*
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8707
                 * wR, wG and wB is the wanted r/g/b value;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8708
                 */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8709
                idx = pix+pix+pix;  /* pix * 3 */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8710
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8711
                __wR = __wantR = rgbP[idx] + __eR;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8712
                __wG = __wantG = rgbP[idx+1] + __eG;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8713
                __wB = __wantB = rgbP[idx+2] + __eB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8714
                if(__wR > 255) __wR = 255;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8715
                else if (__wR < 0) __wR = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8716
                if(__wG > 255) __wG = 255;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8717
                else if (__wG < 0) __wG = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8718
                if(__wB > 255) __wB = 255;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8719
                else if (__wB < 0) __wB = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8720
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8721
                __iR = __wR >> (8-BITSR);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8722
                __iG = __wG >> (8-BITSG);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8723
                __iB = __wB >> (8-BITSB);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8724
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8725
                cubeIndex = (__iR<<SHR) + (__iG<<SHG) + __iB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8726
                subCubeColors = __cube[cubeIndex];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8727
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8728
                if (subCubeColors == nil) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8729
                    /* search around in spirals, for the first match */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8730
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8731
                    delta = 1;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8732
                    while (delta < MAXRGB) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8733
                        /* check plane above */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8734
                        cR = __iR + delta;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8735
                        if ((unsigned)cR < NR) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8736
                            for (cG=__iG-delta; cG<=__iG+delta; cG++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8737
                                if ((unsigned)cG < NG) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8738
                                    for (cB=__iB-delta; cB<=__iB+delta; cB++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8739
                                        if ((unsigned)cB < NB) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8740
                                            cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8741
                                            subCubeColors = __cube[cubeIndex2];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8742
                                            if (__isNonNilObject(subCubeColors)) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8743
                                                goto found;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8744
                                            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8745
                                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8746
                                    }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8747
                                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8748
                            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8749
                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8750
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8751
                        /* check plane below */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8752
                        cR = __iR - delta;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8753
                        if ((unsigned)cR < NR) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8754
                            for (cG=__iG-delta; cG<=__iG+delta; cG++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8755
                                if ((unsigned)cG < NG) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8756
                                    for (cB=__iB-delta; cB<=__iB+delta; cB++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8757
                                        if ((unsigned)cB < NB) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8758
                                            cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8759
                                            subCubeColors = __cube[cubeIndex2];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8760
                                            if (__isNonNilObject(subCubeColors)) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8761
                                                goto found;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8762
                                            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8763
                                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8764
                                    }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8765
                                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8766
                            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8767
                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8768
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8769
                        /* check plane to the right */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8770
                        cG = __iG + delta;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8771
                        if ((unsigned)cG < NG) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8772
                            for (cR=__iR-delta+1; cR<=__iR+delta-1; cR++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8773
                                if ((unsigned)cR < NR) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8774
                                    for (cB=__iB-delta; cB<=__iB+delta; cB++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8775
                                        if ((unsigned)cB < NB) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8776
                                            cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8777
                                            subCubeColors = __cube[cubeIndex2];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8778
                                            if (__isNonNilObject(subCubeColors)) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8779
                                                goto found;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8780
                                            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8781
                                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8782
                                    }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8783
                                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8784
                            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8785
                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8786
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8787
                        /* check plane to the left */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8788
                        cG = __iG - delta;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8789
                        if ((unsigned)cG < NG) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8790
                            for (cR=__iR-delta+1; cR<=__iR+delta-1; cR++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8791
                                if ((unsigned)cR < NR) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8792
                                    for (cB=__iB-delta; cB<=__iB+delta; cB++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8793
                                        if ((unsigned)cB < NB) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8794
                                            cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8795
                                            subCubeColors = __cube[cubeIndex2];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8796
                                            if (__isNonNilObject(subCubeColors)) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8797
                                                goto found;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8798
                                            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8799
                                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8800
                                    }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8801
                                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8802
                            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8803
                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8804
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8805
                        /* check plane at back */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8806
                        cB = __iB + delta;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8807
                        if ((unsigned)cB < NB) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8808
                            for (cR=__iR-delta+1; cR<=(__iR+delta-1); cR++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8809
                                if ((unsigned)cR < NR) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8810
                                    for (cG=__iG-delta+1; cG<=(__iG+delta-1); cG++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8811
                                        if ((unsigned)cG < NG) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8812
                                            cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8813
                                            subCubeColors = __cube[cubeIndex2];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8814
                                            if (__isNonNilObject(subCubeColors)) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8815
                                                goto found;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8816
                                            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8817
                                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8818
                                    }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8819
                                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8820
                            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8821
                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8822
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8823
                        /* check plane at front */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8824
                        cB = __iB - delta;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8825
                        if ((unsigned)cB < NB) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8826
                            for (cR=__iR-delta+1; cR<=(__iR+delta-1); cR++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8827
                                if ((unsigned)cR < NR) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8828
                                    for (cG=__iG-delta+1; cG<=(__iG+delta-1); cG++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8829
                                        if ((unsigned)cG < NG) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8830
                                            cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8831
                                            subCubeColors = __cube[cubeIndex2];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8832
                                            if (__isNonNilObject(subCubeColors)) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8833
                                                goto found;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8834
                                            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8835
                                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8836
                                    }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8837
                                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8838
                            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8839
                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8840
                        delta = delta + 1;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8841
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8842
                    }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8843
                    /* cannot happen - will lead to a segmentation violation ... */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8844
                    subCubeColors = nil;
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8845
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8846
    found:
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8847
                    __iR = cR;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8848
                    __iG = cG;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8849
                    __iB = cB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8850
                    bestIdx = __ByteArrayInstPtr(subCubeColors)->ba_element[0];
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8851
#ifdef REMEMBER_SEARCH
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8852
                    __cube[cubeIndex] = __MKSMALLINT(bestIdx);
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8853
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8854
                } else {
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8855
#ifdef REMEMBER_SEARCH
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8856
                    if (__isSmallInteger(subCubeColors)) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8857
                        bestIdx = __intVal(subCubeColors);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8858
                    } else
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8859
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8860
                    {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8861
                        bestIdx = __ByteArrayInstPtr(subCubeColors)->ba_element[0];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8862
                    }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8863
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8864
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8865
                /*
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8866
                 * ok, now, we have found a collection of nearby
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8867
                 * colors in subCubeColors.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8868
                 *
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8869
                 * since the error is at most 1/16 (i.e. roughly 6%),
7659
01fe20eef85d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7640
diff changeset
  8870
                 * don't care for searching the best - simply take the
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8871
                 * first color found there.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8872
                 * (statistic reduces the error to even a smaller value).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8873
                 * There is no real problem due to that error, since
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8874
                 * it will be diffused anyway ...
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8875
                 */
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8876
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8877
#ifndef NO_FLOYD_STEINBERG
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8878
                {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8879
                    unsigned char *dp;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8880
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8881
                    /*
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8882
                     * fetch that colors r/g/b components
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8883
                     */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8884
                    dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8885
                    dp += bestIdx * 3;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8886
                    __dR = dp[0];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8887
                    __dG = dp[1];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8888
                    __dB = dp[2];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8889
                }
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8890
#endif
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8891
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8892
/*
4725
c8896df7bd3f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4717
diff changeset
  8893
console_fprintf(stderr, "want: %d/%d/%d (%d/%d/%d) got: %d/%d/%d\n",
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8894
                __wantR, __wantG, __wantB,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8895
                __wR, __wG, __wB,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8896
                __dR, __dG, __dB);
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8897
*/
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8898
                /*
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8899
                 * store the corresponding dither colors colorId
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8900
                 */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8901
                *dstP++ = idP[bestIdx];
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8902
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8903
#ifndef NO_FLOYD_STEINBERG
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8904
                /*
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8905
                 * the new error & distribute the error
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8906
                 */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8907
                __eR = __wantR - __dR;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8908
                if (__eR) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8909
                    tR = __eR >> 4;  /* 16th of error */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8910
                    nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8911
                    eP[0] = tR*5;         /* 5/16th for (x / y+1) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8912
                    eP[-3] = tR*3;        /* 3/16th for (x-1 / y+1) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8913
                    eP[3] = __eR - (tR*15);  /* 1/16th for (x+1 / y+1) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8914
                    __eR = nR;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8915
                } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8916
                    __eR = eP[3];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8917
                    eP[0] = eP[-3] = eP[3] = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8918
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8919
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8920
                __eG = __wantG - __dG;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8921
                if (__eG) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8922
                    tG = __eG >> 4;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8923
                    nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8924
                    eP[1] = tG*5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8925
                    eP[-2] = tG*3;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8926
                    eP[4] = __eG - (tG*15);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8927
                    __eG = nG;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8928
                } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8929
                    __eG = eP[4];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8930
                    eP[1] = eP[-2] = eP[4] = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8931
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8932
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8933
                __eB = __wantB - __dB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8934
                if (__eB) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8935
                    tB = __eB >> 4;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8936
                    nB = eP[5] + (tB * 7);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8937
                    eP[2] = tB*5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8938
                    eP[-1] = tB*3;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8939
                    eP[5] = __eB - (tB*15);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8940
                    __eB = nB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8941
                } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8942
                    __eB = eP[5];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8943
                    eP[2] = eP[-1] = eP[5] = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8944
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8945
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8946
                eP += 3;
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8947
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8948
            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8949
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8950
            /*
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8951
             * allow for an interrupt after every row.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8952
             * but care to refetch C variables
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8953
             */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8954
            if (InterruptPending) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8955
                int d_srcP = srcP - __ByteArrayInstPtr(__INST(bytes))->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8956
                int d_dstP = dstP - __ByteArrayInstPtr(pseudoBits)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8957
                int d_errP = errP - (short *) __ByteArrayInstPtr(error)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8958
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8959
                __interrupt__();
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8960
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8961
                srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element + d_srcP;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8962
                dstP = __ByteArrayInstPtr(pseudoBits)->ba_element + d_dstP;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8963
                rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8964
                idP = __ByteArrayInstPtr(ditherIds)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8965
                errP = (short *) __ByteArrayInstPtr(error)->ba_element + d_errP;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8966
                __cube = __ArrayInstPtr(cube)->a_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8967
            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8968
        }
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8969
    }
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8970
%}.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8971
    failed ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8972
        self primitiveFailed.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8973
        ^ nil
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8974
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8975
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8976
    ^ pseudoBits
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8977
!
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8978
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8979
orderedDitheredGrayBitsDepth:depth
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8980
    "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
  8981
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8982
    ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8983
        orderedDitheredGrayBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8984
        ditherWidth:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8985
        depth:depth.
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8986
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8987
    "Created: 24.6.1997 / 22:20:12 / cg"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8988
!
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8989
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8990
orderedDitheredGrayBitsWithDitherMatrix:ditherMatrix ditherWidth:dW depth:depth
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8991
    "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
  8992
     with a constant ditherMatrix, this can be used for thresholding.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8993
     Works for any source depths / photometric,
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8994
     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
  8995
     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
  8996
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8997
    |dH nDither
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8998
     greyLevels greyValues greyPixels greyErrors
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8999
     dstIndex        "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9000
     nextDst
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9001
     bytesPerOutRow  "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9002
     pixelsPerByte   "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9003
     outBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9004
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9005
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9006
     bitCnt          "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9007
     byte            "{Class: SmallInteger }" |
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9008
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9009
    depth > 8 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9010
        'IMAGE: unimplemented orderedDither conversion' errorPrintCR.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9011
        ^ nil
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9012
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9013
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9014
    nDither := ditherMatrix size.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9015
    dH := nDither / dW.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9016
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9017
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9018
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9019
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9020
    greyLevels := 1 bitShift:depth.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9021
    pixelsPerByte := 8 / depth.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9022
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9023
    bytesPerOutRow := (w * depth + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9024
    outBits := ByteArray uninitializedNew:(bytesPerOutRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9025
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9026
    dstIndex := 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9027
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9028
    self bitsPerPixel <= 12 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9029
        "/ fetch scaled brightness values outside of loop into a table;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9030
        "/ use table-value in loop
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9031
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9032
        greyValues := self greyMapForRange:(greyLevels-1).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9033
        greyPixels := greyValues collect:[:v | v isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9034
                                                   0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9035
                                               ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9036
                                                   v truncated]].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9037
        greyPixels := ByteArray withAll:greyPixels.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9038
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9039
        greyErrors := greyValues collect:[:v | v isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9040
                                                   0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9041
                                               ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9042
                                                   ((v - v truncated) * nDither) rounded
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9043
                                               ]].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9044
        greyErrors := ByteArray withAll:greyErrors.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9045
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9046
        0 to:(h-1) do:[:y |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9047
            nextDst := dstIndex + bytesPerOutRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9048
            byte := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9049
            bitCnt := 8.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9050
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9051
            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
  9052
%{
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9053
                int __dW = __intVal(dW);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9054
                int __byte = __intVal(byte);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9055
                /* Note: __value is reserved in Visual C++ 8 (2005) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9056
                int __val = __intVal(value);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9057
                int __dT;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9058
                int __dstIdx;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9059
                int __pixel, __grey;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9060
                int __bitCnt = __intVal(bitCnt);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9061
                unsigned char *__greyPixels = __ByteArrayInstPtr(greyPixels)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9062
                unsigned char *__greyErrors = __ByteArrayInstPtr(greyErrors)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9063
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9064
                __pixel = __greyPixels[__val];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9065
                __grey = __greyErrors[__val];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9066
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9067
                __dT = __ByteArrayInstPtr(ditherMatrix)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9068
                            ->ba_element[__intVal(x) % __dW
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9069
                                         + (__intVal(y) % __intVal(dH)) * __dW];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9070
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9071
                if (__grey > __dT) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9072
                    __pixel++;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9073
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9074
                __byte = (__byte << __intVal(depth)) | __pixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9075
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9076
                __bitCnt = __bitCnt - __intVal(depth);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9077
                if (__bitCnt == 0) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9078
                    __dstIdx = __intVal(dstIndex);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9079
                    __ByteArrayInstPtr(outBits)->ba_element[__dstIdx-1] = __byte;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9080
                    __dstIdx = __dstIdx + 1;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9081
                    dstIndex = __MKSMALLINT(__dstIdx);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9082
                    __byte = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9083
                    __bitCnt = 8;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9084
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9085
                byte = __MKSMALLINT(__byte);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9086
                bitCnt = __MKSMALLINT(__bitCnt);
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9087
%}.
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9088
                0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9089
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9090
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9091
            bitCnt ~~ 8 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9092
                byte := byte bitShift:bitCnt.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9093
                outBits at:dstIndex put:byte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9094
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9095
            dstIndex := nextDst.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9096
        ].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9097
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9098
        'Image [info]: slow ordered dither ..' infoPrintCR.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9099
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9100
        0 to:(h-1) do:[:y |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9101
            nextDst := dstIndex + bytesPerOutRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9102
            byte := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9103
            bitCnt := 8.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9104
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9105
            "/ this is the representaion independent (but slow)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9106
            "/ inner loop - it extracts colors from the receiver
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9107
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9108
            self colorsAtY:y from:0 to:(w-1) do:[:x :clr |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9109
                |dstClr grey dT pixel|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9110
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9111
                "/ get the colors grey value [0 .. 1]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9112
                grey := clr brightness.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9113
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9114
                "/ remap into [0 .. greyLevels-1]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9115
                grey := grey * (greyLevels-1).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9116
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9117
                "/ get threshold pixel [0 .. greyLevels-1]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9118
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9119
                pixel := grey truncated.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9120
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9121
                "/ compute the error [0..1]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9122
                grey := grey - pixel.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9123
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9124
                "/ map into dither space [0 .. nDither]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9125
                grey := (grey * (nDither)) rounded.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9126
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9127
%{
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9128
                int __dW = __intVal(dW);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9129
                int __byte = __intVal(byte);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9130
                int __dT;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9131
                int __dstIdx;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9132
                int __pixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9133
                int __bitCnt = __intVal(bitCnt);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9134
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9135
                __dT = __ByteArrayInstPtr(ditherMatrix)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9136
                            ->ba_element[__intVal(x) % __dW
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9137
                                         + (__intVal(y) % __intVal(dH)) * __dW];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9138
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9139
                __pixel = __intVal(pixel);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9140
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9141
                if (__intVal(grey) > __dT) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9142
                    __pixel++;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9143
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9144
                __byte = (__byte << __intVal(depth)) | __pixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9145
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9146
                __bitCnt = __bitCnt - __intVal(depth);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9147
                if (__bitCnt == 0) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9148
                    __dstIdx = __intVal(dstIndex);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9149
                    __ByteArrayInstPtr(outBits)->ba_element[__dstIdx-1] = __byte;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9150
                    __dstIdx = __dstIdx + 1;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9151
                    dstIndex = __MKSMALLINT(__dstIdx);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9152
                    __byte = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9153
                    __bitCnt = 8;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9154
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9155
                byte = __MKSMALLINT(__byte);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9156
                bitCnt = __MKSMALLINT(__bitCnt);
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9157
%}.
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9158
                0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9159
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9160
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9161
            bitCnt ~~ 8 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9162
                byte := byte bitShift:bitCnt.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9163
                outBits at:dstIndex put:byte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9164
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9165
            dstIndex := nextDst.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9166
        ].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9167
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9168
    ^ outBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9169
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9170
831
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  9171
orderedDitheredMonochromeBits
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  9172
    "return the bitmap for a dithered monochrome bitmap from the image;
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  9173
     using a default ditherMatrix."
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  9174
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  9175
    ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9176
        orderedDitheredMonochromeBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9177
        ditherWidth:8
831
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  9178
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  9179
    "Created: 11.6.1996 / 16:48:57 / cg"
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  9180
!
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  9181
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9182
orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9183
    "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
  9184
     with a constant ditherMatrix, this can be used for thresholding.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9185
     Works for any source depths / photometric,
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9186
     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
  9187
     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
  9188
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9189
    |dH nDither
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9190
     greyValues
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9191
     dstIndex        "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9192
     nextDst         "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9193
     bytesPerMonoRow "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9194
     monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9195
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9196
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9197
     bitCnt          "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9198
     byte            "{Class: SmallInteger }" |
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9199
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9200
    nDither := ditherMatrix size.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9201
    dH := nDither / dW.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9202
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9203
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9204
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9205
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9206
    bytesPerMonoRow := (w + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9207
    monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9208
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9209
    dstIndex := 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9210
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9211
    self bitsPerPixel <= 12 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9212
        "/ fetch scaled brightness values outside of loop into a table;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9213
        "/ use table-value in loop
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9214
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9215
        greyValues := self greyByteMapForRange:nDither.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9216
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9217
        0 to:(h-1) do:[:y |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9218
            nextDst := dstIndex + bytesPerMonoRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9219
            byte := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9220
            bitCnt := 8.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9221
            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
  9222
%{
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9223
                int __dW = __intVal(dW);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9224
                int __byte = __intVal(byte);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9225
                int __dT;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9226
                int __dstIdx;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9227
                int __bitCnt = __intVal(bitCnt);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9228
                int __grey;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9229
                unsigned char *__greyValues = __ByteArrayInstPtr(greyValues)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9230
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9231
                __grey = __greyValues[__intVal(value)];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9232
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9233
                __dT = __ByteArrayInstPtr(ditherMatrix)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9234
                            ->ba_element[__intVal(x) % __dW
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9235
                                         + (__intVal(y) % __intVal(dH)) * __dW];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9236
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9237
                __byte = __byte << 1;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9238
                if (__grey > __dT) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9239
                    __byte = __byte | 1;            /* white */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9240
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9241
                __bitCnt = __bitCnt - 1;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9242
                if (__bitCnt == 0) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9243
                    __dstIdx = __intVal(dstIndex);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9244
                    __ByteArrayInstPtr(monoBits)->ba_element[__dstIdx-1] = __byte;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9245
                    __dstIdx = __dstIdx + 1;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9246
                    dstIndex = __MKSMALLINT(__dstIdx);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9247
                    __byte = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9248
                    __bitCnt = 8;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9249
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9250
                byte = __MKSMALLINT(__byte);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9251
                bitCnt = __MKSMALLINT(__bitCnt);
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9252
%}.
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9253
                0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9254
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9255
            bitCnt ~~ 8 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9256
                byte := byte bitShift:bitCnt.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9257
                monoBits at:dstIndex put:byte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9258
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9259
            dstIndex := nextDst.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9260
        ].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9261
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9262
        'Image [info]: slow ordered dither ..' infoPrintCR.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9263
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9264
        0 to:(h-1) do:[:y |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9265
            nextDst := dstIndex + bytesPerMonoRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9266
            byte := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9267
            bitCnt := 8.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9268
            self colorsAtY:y from:0 to:(w-1) do:[:x :clr |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9269
                |dstClr grey dT|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9270
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9271
                "/ get the colors grey value [0 .. 1]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9272
                grey := clr brightness.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9273
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9274
                "/ map into dither space [0 .. nDither]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9275
                grey := (grey * (nDither)) rounded.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9276
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9277
%{
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9278
                int __dW = __intVal(dW);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9279
                int __byte = __intVal(byte);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9280
                int __dT;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9281
                int __dstIdx;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9282
                int __bitCnt = __intVal(bitCnt);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9283
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9284
                __dT = __ByteArrayInstPtr(ditherMatrix)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9285
                            ->ba_element[__intVal(x) % __dW
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9286
                                         + (__intVal(y) % __intVal(dH)) * __dW];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9287
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9288
                __byte = __byte << 1;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9289
                if (__intVal(grey) > __dT) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9290
                    __byte = __byte | 1;            /* white */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9291
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9292
                __bitCnt = __bitCnt - 1;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9293
                if (__bitCnt == 0) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9294
                    __dstIdx = __intVal(dstIndex);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9295
                    __ByteArrayInstPtr(monoBits)->ba_element[__dstIdx-1] = __byte;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9296
                    __dstIdx = __dstIdx + 1;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9297
                    dstIndex = __MKSMALLINT(__dstIdx);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9298
                    __byte = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9299
                    __bitCnt = 8;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9300
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9301
                byte = __MKSMALLINT(__byte);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9302
                bitCnt = __MKSMALLINT(__bitCnt);
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9303
%}.
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9304
                0
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9305
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9306
"/                dT := ditherMatrix at:(x \\ dW) + (y \\ dH * dW) + 1.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9307
"/
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9308
"/                byte := byte bitShift:1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9309
"/                grey < dT ifTrue:[
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9310
"/                    byte := byte bitOr:1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9311
"/                ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9312
"/                bitCnt := bitCnt - 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9313
"/                bitCnt == 0 ifTrue:[
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9314
"/                    monoBits at:dstIndex put:byte.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9315
"/                    dstIndex := dstIndex + 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9316
"/                    byte := 0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9317
"/                    bitCnt := 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9318
"/                ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9319
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9320
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9321
            bitCnt ~~ 8 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9322
                byte := byte bitShift:bitCnt.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9323
                monoBits at:dstIndex put:byte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9324
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9325
            dstIndex := nextDst.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9326
        ].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9327
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9328
    ^ monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9329
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9330
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9331
stevensonArceDitheredMonochromeBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9332
    "return the bitmap for a dithered monochrome bitmap from the image.
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9333
     Works for any source depths / photometric.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9334
     TODO: move to separate dither helper class"
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9335
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  9336
    |dstIndex        "{Class: SmallInteger }"
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9337
     nextDst         "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9338
     bytesPerMonoRow "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9339
     monoBits greyValues
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9340
     errorArray
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9341
     errorArray1 errorArray2 errorArray3
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9342
     e t
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9343
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9344
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9345
     bitCnt          "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9346
     byte            "{Class: SmallInteger }"
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  9347
     grey
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  9348
     xE              "{Class: SmallInteger }" |
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9349
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9350
    self depth > 12 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9351
        ^ self floydSteinbergDitheredMonochromeBits
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9352
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9353
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9354
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9355
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9356
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9357
    bytesPerMonoRow := (w + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9358
    monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9359
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9360
    errorArray := Array new:(w+6).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9361
    errorArray1 := Array new:(w+6) withAll:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9362
    errorArray2 := Array new:(w+6) withAll:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9363
    errorArray3 := Array new:(w+6) withAll:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9364
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9365
    dstIndex := 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9366
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9367
    "/ 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
  9368
    "/ use table-value in loop
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9369
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9370
    greyValues := self greyMapForRange:(255 * 1024).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9371
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9372
    0 to:(h-1) do:[:y |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9373
        nextDst := dstIndex + bytesPerMonoRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9374
        byte := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9375
        bitCnt := 8.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9376
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9377
        t := errorArray.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9378
        errorArray := errorArray1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9379
        errorArray1 := errorArray2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9380
        errorArray2 := errorArray3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9381
        errorArray3 := t.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9382
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9383
        errorArray3 atAllPut:0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9384
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9385
        self valuesAtY:y from:0 to:(w-1) do:[:x :pixel |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9386
            |eP eD|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9387
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9388
            "/ get the colors grey value [0 .. 1]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9389
            grey := greyValues at:(pixel + 1).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9390
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9391
            "/ adjust error
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9392
            xE := x + 3 + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9393
            grey := (grey + (errorArray at:xE)).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9394
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9395
            byte := byte bitShift:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9396
            grey > (127 * 1024) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9397
                byte := byte bitOr:1.      "/ white
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9398
                e := grey - (255 * 1024)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9399
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9400
                e := grey                  "/ black
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9401
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9402
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9403
            e ~= 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9404
                "/ distribute the error:
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9405
                "/                  XX    32
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9406
                "/         12    26    30    16
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9407
                "/            12    26    12
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9408
                "/          5    12    12     5
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9409
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9410
                eD := e.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9411
                e := e // 200.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9412
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9413
                eP := e * 32. eD := eD - eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9414
                errorArray at:xE+2 put:(errorArray at:xE+2) + eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9415
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9416
                eP := e * 30. eD := eD - eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9417
                errorArray1 at:xE+1 put:(errorArray1 at:xE+1) + eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9418
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9419
                eP := e * 16. eD := eD - eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9420
                errorArray1 at:xE+3 put:(errorArray1 at:xE+3) + eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9421
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9422
                eP := e * 26. eD := eD - eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9423
                errorArray1 at:xE-1 put:(errorArray1 at:xE-1) + eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9424
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9425
                eD := eD - eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9426
                errorArray2 at:xE put:(errorArray2 at:xE) + eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9427
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9428
                eP := e * 12. eD := eD - eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9429
                errorArray1 at:xE-3 put:(errorArray1 at:xE-3) + eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9430
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9431
                eD := eD - eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9432
                errorArray2 at:xE-2 put:(errorArray2 at:xE-2) + eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9433
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9434
                eD := eD - eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9435
                errorArray2 at:xE+2 put:(errorArray2 at:xE+2) + eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9436
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9437
                eD := eD - eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9438
                errorArray3 at:xE-1 put:(errorArray3 at:xE-1) + eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9439
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9440
                eD := eD - eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9441
                errorArray3 at:xE+1 put:(errorArray3 at:xE+1) + eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9442
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9443
                eP := e * 5. eD := eD - eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9444
                errorArray3 at:xE-3 put:(errorArray3 at:xE-3) + eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9445
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9446
                eP := eD.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9447
                errorArray3 at:xE+3 put:(errorArray3 at:xE+3) + eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9448
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9449
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9450
            bitCnt := bitCnt - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9451
            bitCnt == 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9452
                monoBits at:dstIndex put:byte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9453
                dstIndex := dstIndex + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9454
                byte := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9455
                bitCnt := 8.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9456
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9457
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9458
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9459
        bitCnt ~~ 8 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9460
            byte := byte bitShift:bitCnt.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9461
            monoBits at:dstIndex put:byte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9462
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9463
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9464
        dstIndex := nextDst.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9465
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9466
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9467
    ^ monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9468
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9469
    "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
  9470
    "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
  9471
! !
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9472
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9473
!Image methodsFor:'drawing'!
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9474
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9475
displayArcOrigin:origin corner:corner from:startAngle angle:angle withColor:aColor
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9476
    "draw a circle with some pixel value.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9477
     By using a tempForm, we assure that the same pixel algorithm is used as in a window"
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9478
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9479
    self displayArcOrigin:origin corner:corner from:startAngle angle:angle withValue:(self valueFromColor:aColor)
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9480
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9481
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9482
     |cm i|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9483
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9484
     cm :=  Array with:Color white with:Color black with:Color red.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9485
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9486
     i := Depth8Image extent:300@400 depth:8 palette:cm.
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9487
     i displayArcOrigin:100@100 corner:200@200 from:0 angle:90 withColor:Color red.
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9488
     i inspect.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9489
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9490
!
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9491
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9492
displayArcOrigin:origin corner:corner from:startAngle angle:angle withValue:aPixelValueOrNil
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9493
    "draw a circle with some pixel value.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9494
     By using a tempForm, we assure that the same pixel algorithm is used as in a window.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9495
     If aPixelValueOrNil is nil, the mask pixel will be set to 0 (transparent),
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9496
     otherwise to 1. (used by the bitmap editor)"
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9497
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9498
    |tempForm wI "{ Class: SmallInteger }"
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9499
     hI "{ Class: SmallInteger }" tempImage|
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9500
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9501
    wI := self width.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9502
    hI := self height.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9503
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9504
    tempForm := Form width:wI height:hI depth:1 onDevice:Screen current.
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  9505
    tempForm
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9506
        paint:(Color colorId:1) on:(Color colorId:0);
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9507
        clear.
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9508
    tempForm displayArcOrigin:origin corner:corner from:startAngle angle:angle.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9509
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9510
    tempImage := tempForm asImage.
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9511
    0 to:hI-1 do:[:yRun|
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9512
        0 to:wI-1 do:[:xRun|
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9513
            (tempImage pixelAtX:xRun y:yRun) == 1 ifTrue:[
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9514
                self atImageAndMask:xRun@yRun putValue:aPixelValueOrNil.
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9515
            ].
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9516
        ].
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9517
    ].
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9518
    tempForm destroy.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9519
    tempImage close.
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9520
    self release. "/ device-image is no longer valid
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9521
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9522
    "
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9523
     |cm i|
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9524
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9525
     cm :=  Array with:Color white with:Color black with:Color red.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9526
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9527
     i := Depth8Image extent:300@400 depth:8 palette:cm.
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9528
     i displayArcOrigin:100@100 corner:200@200 from:0 angle:90 withColor:Color red.
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9529
     i inspect.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9530
    "
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9531
!
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9532
4994
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9533
drawEllipse:aRectangle withColor:aColor
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9534
    "draw a circle with some pixel value.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9535
     By using a tempForm, we assure that the same pixel algorithm is used as in a window"
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9536
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9537
    self drawEllipse:aRectangle withValue:(self valueFromColor:aColor)
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9538
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9539
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9540
     |cm i|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9541
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9542
     cm :=  Array with:Color white with:Color black with:Color red.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9543
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9544
     i := Depth8Image extent:300@400 depth:8 palette:cm.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9545
     i drawEllipse:(0@0 corner:80@100) withColor:Color red.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9546
     i inspect.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9547
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9548
!
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9549
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9550
drawEllipse:aRectangle withValue:aPixelValueOrNil
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9551
    "draw a circle with some pixel value.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9552
     By using a tempForm, we assure that the same pixel algorithm is used as in a window.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9553
     If aPixelValueOrNil is nil, the mask pixel will be set to 0 (transparent),
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9554
     otherwise to 1. (used by the bitmap editor)"
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9555
4994
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9556
    |tempForm xI "{ Class: SmallInteger }"
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9557
     yI "{ Class: SmallInteger }"
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9558
     wI "{ Class: SmallInteger }"
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9559
     hI "{ Class: SmallInteger }" tempImage|
4994
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9560
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9561
    wI := aRectangle width.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9562
    hI := aRectangle height.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9563
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9564
    tempForm := Form width:wI height:hI depth:1 onDevice:Screen current.
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  9565
    tempForm
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9566
        paint:(Color colorId:1) on:(Color colorId:0);
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9567
        clear.
4994
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9568
    tempForm displayArcIn:(0@0 extent:wI@hI) from:0 angle:360.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9569
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9570
    xI := aRectangle left.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9571
    yI := aRectangle top.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9572
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9573
    tempImage := tempForm asImage.
4994
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9574
    0 to:hI-1 do:[:yRun|
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9575
        0 to:wI-1 do:[:xRun|
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9576
            (tempImage pixelAtX:xRun y:yRun) == 1 ifTrue:[
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9577
                self atImageAndMask: (xI+xRun)@(yI+yRun) putValue:aPixelValueOrNil.
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9578
            ].
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9579
        ].
4994
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9580
    ].
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9581
    tempForm destroy.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9582
    tempImage close.
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9583
    self release. "/ device-image is no longer valid
4994
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9584
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9585
    "
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9586
     |cm i|
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9587
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9588
     cm :=  Array with:Color white with:Color black with:Color red.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9589
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9590
     i := Depth8Image extent:300@400 depth:8 palette:cm.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9591
     i drawEllipse:(0@0 corner:80@100) withColor:Color red.
4994
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9592
     i inspect.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9593
    "
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9594
!
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9595
5235
e9ab91666ebf *** empty log message ***
sr
parents: 5216
diff changeset
  9596
drawLineFrom:startPoint to:endPoint withColor:aColorOrPixelValue
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9597
    "draw a line with some pixel value.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9598
     This is in no way tuned, as normally, display-forms are used to draw.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9599
     The only use for this is when we have to generate images in a headless webService
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9600
     (such as the HumanReadableImageGenerator)"
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9601
5235
e9ab91666ebf *** empty log message ***
sr
parents: 5216
diff changeset
  9602
    |pixelValue|
e9ab91666ebf *** empty log message ***
sr
parents: 5216
diff changeset
  9603
e9ab91666ebf *** empty log message ***
sr
parents: 5216
diff changeset
  9604
    pixelValue := aColorOrPixelValue.
e9ab91666ebf *** empty log message ***
sr
parents: 5216
diff changeset
  9605
    pixelValue isInteger ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9606
        pixelValue := self valueFromColor:aColorOrPixelValue
5235
e9ab91666ebf *** empty log message ***
sr
parents: 5216
diff changeset
  9607
    ].
e9ab91666ebf *** empty log message ***
sr
parents: 5216
diff changeset
  9608
    self drawLineFrom:startPoint to:endPoint withValue:pixelValue
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9609
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9610
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9611
     |i|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9612
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9613
     i := Depth1Image extent:100@100 depth:1 palette:nil.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9614
     i photometric:#blackIs0.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9615
     i drawLineFrom:5@5 to:94@5 withColor:1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9616
     i drawLineFrom:94@5 to:94@94 withColor:1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9617
     i drawLineFrom:94@94 to:5@94 withColor:1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9618
     i drawLineFrom:5@94 to:5@5 withColor:1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9619
     i drawLineFrom:10@10 to:90@90 withColor:1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9620
     i drawLineFrom:90@10 to:10@90 withColor:1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9621
     i inspect.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9622
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9623
!
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9624
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9625
drawLineFrom:startPoint to:endPoint withValue:aPixelValueOrNil
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9626
    "draw a line with some pixel value.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9627
     This is in no way tuned, as normally, display-forms are used to draw.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9628
     The only use for this is when we have to generate images in a headless webService
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9629
     (such as the HumanReadableImageGenerator).
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9630
     If aPixelValueOrNil is nil, the mask pixel will be set to 0 (transparent),
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9631
     otherwise to 1. (used by the bitmap editor)"
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9632
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9633
    |x0 x1 y0 y1 t steep deltax deltay error deltaerr ystep y|
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9634
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9635
    x0 := startPoint x.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9636
    y0 := startPoint y.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9637
    x1 := endPoint x.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9638
    y1 := endPoint y.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9639
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9640
    steep := (y1 - y0) abs > (x1 - x0) abs.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9641
    steep ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9642
        t := x0. x0 := y0. y0 := t.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9643
        t := x1. x1 := y1. y1 := t.
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9644
    ].
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9645
    x0 > x1 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9646
        t := x0. x0 := x1. x1 := t.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9647
        t := y0. y0 := y1. y1 := t.
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9648
    ].
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9649
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9650
    deltax := x1 - x0.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9651
    deltay := (y1 - y0) abs.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9652
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9653
    deltax == 0 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9654
        y0 to: y1 do:[:y |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9655
            self atImageAndMask:x0@y putValue:aPixelValueOrNil.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9656
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9657
        ^ self.
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9658
    ].
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9659
    deltay == 0 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9660
        x0 to: x1 do:[:x |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9661
            self atImageAndMask:x@y0 putValue:aPixelValueOrNil.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9662
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9663
        ^ self.
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9664
    ].
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9665
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9666
    error := 0.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9667
    deltaerr := deltay / deltax.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9668
    y := y0.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9669
    y0 < y1 ifTrue:[ ystep := 1 ] ifFalse:[ ystep := -1 ].
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9670
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9671
    x0 to: x1 do:[:x |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9672
        steep ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9673
            self atImageAndMask:y@x putValue:aPixelValueOrNil.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9674
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9675
            self atImageAndMask:x@y putValue:aPixelValueOrNil.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9676
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9677
        error := error + deltaerr.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9678
        error >= 0.5 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9679
            y := y + ystep.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9680
            error := error - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9681
        ]
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9682
    ].
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9683
    self release. "/ device-image is no longer valid
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9684
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9685
    "
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9686
     |i|
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9687
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9688
     i := Depth1Image extent:100@100 depth:1 palette:nil.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9689
     i photometric:#blackIs0.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9690
     i drawLineFrom:5@5 to:94@5 withColor:1.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9691
     i drawLineFrom:94@5 to:94@94 withColor:1.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9692
     i drawLineFrom:94@94 to:5@94 withColor:1.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9693
     i drawLineFrom:5@94 to:5@5 withColor:1.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9694
     i drawLineFrom:10@10 to:90@90 withColor:1.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9695
     i drawLineFrom:90@10 to:10@90 withColor:1.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9696
     i inspect.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9697
    "
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9698
!
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9699
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9700
drawRectangle: aRectangle withColor:aColor
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9701
    "draw a rectangle with some pixel value.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9702
     By using #atImageAndMask:put: it also works on images with mono masks."
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9703
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9704
    self drawRectangle:aRectangle withValue:(self valueFromColor:aColor)
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9705
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9706
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9707
     |i|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9708
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9709
     i := Depth1Image extent:100@100 depth:1 palette:nil.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9710
     i photometric:#blackIs0.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9711
     i drawRectangle:(10@10 corner:90@90) withColor:1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9712
     i inspect.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9713
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9714
!
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9715
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9716
drawRectangle: aRectangle withValue:aPixelValueOrNil
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9717
    "draw a rectangle with some pixel value.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9718
     By using #atImageAndMask:put: it also works on images with mono masks.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9719
     If aPixelValueOrNil is nil, the mask pixel will be set to 0 (transparent),
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9720
     otherwise to 1. (used by the bitmap editor)"
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9721
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9722
    |xI "{ Class: SmallInteger }"
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9723
     yI "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9724
     wI "{ Class: SmallInteger }"
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9725
     hI "{ Class: SmallInteger }"|
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9726
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9727
    xI := aRectangle left.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9728
    yI := aRectangle top.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9729
    wI := aRectangle width.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9730
    hI := aRectangle height.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9731
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9732
    xI to:xI+wI-1 do:[:xRun|
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9733
        self atImageAndMask: xRun@yI put:aPixelValueOrNil.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9734
        self atImageAndMask: xRun@(yI+hI-1) put:aPixelValueOrNil
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9735
    ].
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9736
    yI+1 to:yI+hI-2 do:[:yRun|
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9737
        self atImageAndMask: xI@yRun put:aPixelValueOrNil.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9738
        self atImageAndMask: xI+wI-1@yRun put:aPixelValueOrNil
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9739
    ].
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9740
    self release. "/ device-image is no longer valid
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9741
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9742
    "
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9743
     |i|
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9744
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9745
     i := Depth1Image extent:100@100 depth:1 palette:nil.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9746
     i photometric:#blackIs0.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9747
     i drawRectangle:(10@10 corner:90@90) withColor:1.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9748
     i inspect.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9749
    "
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9750
!
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9751
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  9752
fillAntiAliasedArc:origin radius:r from:startAngle angle:angle withColor:aColor colorDictionary:colorDictionary blendStart:blendStart
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9753
    "draw a circle with some pixel value.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9754
     By using a tempForm, we assure that the same pixel algorithm is used as in a window"
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9755
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9756
    |tempForm wI "{ Class: SmallInteger }"
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9757
     hI "{ Class: SmallInteger }"
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9758
     colorValue tempImage|
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9759
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9760
    wI := self width.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9761
    hI := self height.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9762
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9763
    tempForm := Form width:wI height:hI depth:1 onDevice:Screen current.
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  9764
    tempForm
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9765
        paint:(Color colorId:1) on:(Color colorId:0);
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9766
        clear.
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9767
    tempForm fillArc:origin radius:r from:startAngle angle:angle.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9768
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9769
    colorValue := self valueFromColor:aColor.
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9770
    tempImage := tempForm asImage.
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9771
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9772
    0 to:hI-1 do:[:yRun|
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9773
        0 to:wI-1 do:[:xRun|
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9774
            (tempImage pixelAtX:xRun y:yRun) == 1 ifTrue:[
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9775
                self atImageAndMask:xRun@yRun putValue:colorValue.
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9776
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9777
                #(left right) do:[:aHorizontal |
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9778
                    #(top bottom) do:[:aVertical |
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9779
                        self vitualAntiAliasedAlongXvertical:aVertical horizontal:aHorizontal form:tempImage color:aColor xRun:xRun yRun:yRun colorDictionary:colorDictionary blendStart:blendStart.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9780
                        self vitualAntiAliasedAlongYhorizontal:aHorizontal vertical:aVertical form:tempImage color:aColor xRun:xRun yRun:yRun colorDictionary:colorDictionary blendStart:blendStart.
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9781
                    ].
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9782
                ].
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9783
            ].
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9784
        ].
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9785
    ].
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9786
    tempForm destroy.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9787
    tempImage close.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9788
    self release. "/ device-image is no longer valid
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9789
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9790
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9791
    "
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9792
        |colorMap aaImgArray|
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9793
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9794
        colorMap := Array with:Color white with:Color black with:Color red with:Color blue.
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9795
7484
ac97ca090d0c #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 7483
diff changeset
  9796
        aaImgArray := Depth8Image extent:200@200 depth:8 antiAliasedPalette:colorMap bgColor:Color white.
ac97ca090d0c #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 7483
diff changeset
  9797
        aaImgArray last fillAntiAliasedArc:105@95 radius:80 from:0 angle:90 withColor:Color red
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9798
            colorDictionary:aaImgArray first
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9799
            blendStart:aaImgArray second.
7484
ac97ca090d0c #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 7483
diff changeset
  9800
        aaImgArray last fillAntiAliasedArc:100@100 radius:80 from:90 angle:270 withColor:Color blue
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9801
            colorDictionary:aaImgArray first
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9802
            blendStart:aaImgArray second.
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9803
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9804
        aaImgArray last inspect.
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9805
    "
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9806
!
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9807
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9808
fillArc:origin radius:r from:startAngle angle:angle withColor:aColorOrIndex
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9809
    "draw a circle with some pixel value.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9810
     By using a tempForm, we assure that the same pixel algorithm is used as in a window"
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9811
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9812
    |tempForm tempImage
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9813
     wI "{ Class: SmallInteger }"
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9814
     hI "{ Class: SmallInteger }"
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9815
     colorValue|
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9816
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9817
    wI := self width.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9818
    hI := self height.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9819
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9820
    tempForm := Form width:wI height:hI depth:1 onDevice:Screen current.
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  9821
    tempForm
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9822
        paint:(Color colorId:1) on:(Color colorId:0);
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9823
        clear.
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9824
    tempForm fillArc:origin radius:r from:startAngle angle:angle.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9825
4997
15d53562d4e8 changed #fillArc:radius:from:angle:withColor:
sr
parents: 4996
diff changeset
  9826
    aColorOrIndex isInteger ifTrue:[
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9827
        colorValue := aColorOrIndex.
4997
15d53562d4e8 changed #fillArc:radius:from:angle:withColor:
sr
parents: 4996
diff changeset
  9828
    ] ifFalse:[
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9829
        colorValue := self valueFromColor:aColorOrIndex.
4997
15d53562d4e8 changed #fillArc:radius:from:angle:withColor:
sr
parents: 4996
diff changeset
  9830
    ].
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9831
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9832
    tempImage := tempForm asImage.
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9833
    0 to:hI-1 do:[:yRun|
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9834
        0 to:wI-1 do:[:xRun|
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9835
            (tempImage pixelAtX:xRun y:yRun) == 1 ifTrue:[
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9836
                self atImageAndMask:xRun@yRun putValue:colorValue.
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9837
            ].
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9838
        ].
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9839
    ].
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9840
    tempForm destroy.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9841
    tempImage close.
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9842
    self release. "/ device-image is no longer valid
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9843
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9844
    "
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9845
     |cm i|
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9846
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9847
     cm :=  Array with:Color white with:Color black with:Color red with:Color blue.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9848
7484
ac97ca090d0c #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 7483
diff changeset
  9849
     i := Depth8Image extent:200@200 depth:8 palette:cm.
ac97ca090d0c #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 7483
diff changeset
  9850
     i fillArc:105@95 radius:80 from:0 angle:90 withColor:Color red.
ac97ca090d0c #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 7483
diff changeset
  9851
     i fillArc:100@100 radius:80 from:90 angle:270 withColor:Color blue.
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9852
     i inspect.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9853
    "
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9854
!
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9855
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9856
fillEllipse:aRectangle withColor:aColor
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9857
    "draw a circle with some pixel value.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9858
     By using a tempForm, we assure that the same pixel algorithm is used as in a window"
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9859
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9860
    self fillEllipse:aRectangle withValue:(self valueFromColor:aColor)
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9861
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9862
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9863
     |cm i|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9864
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9865
     cm :=  Array with:Color white with:Color black with:Color red.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9866
7484
ac97ca090d0c #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 7483
diff changeset
  9867
     i := Depth8Image extent:100@100 depth:8 palette:cm.
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9868
     i fillEllipse:(0@0 corner:80@100) withColor:Color red.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9869
     i inspect.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9870
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9871
!
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9872
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9873
fillEllipse:aRectangle withValue:aPixelValueOrNil
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9874
    "draw a circle with some pixel value.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9875
     By using a tempForm, we assure that the same pixel algorithm is used as in a window.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9876
     If aPixelValueOrNil is nil, the mask pixel will be set to 0 (transparent),
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9877
     otherwise to 1. (used by the bitmap editor)"
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9878
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9879
    |tempForm xI "{ Class: SmallInteger }"
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9880
     yI "{ Class: SmallInteger }"
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9881
     wI "{ Class: SmallInteger }"
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9882
     hI "{ Class: SmallInteger }" tempImage|
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9883
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9884
    wI := aRectangle width.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9885
    hI := aRectangle height.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9886
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9887
    tempForm := Form width:wI height:hI depth:1 onDevice:Screen current.
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  9888
    tempForm
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9889
        paint:(Color colorId:1) on:(Color colorId:0);
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9890
        clear.
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9891
    tempForm fillArcIn:(0@0 extent:wI@hI) from:0 angle:360.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9892
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9893
    xI := aRectangle left.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9894
    yI := aRectangle top.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9895
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9896
    tempImage := tempForm asImage.
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9897
    0 to:hI-1 do:[:yRun|
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9898
        0 to:wI-1 do:[:xRun|
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9899
            (tempImage pixelAtX:xRun y:yRun) == 1 ifTrue:[
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9900
                self atImageAndMask:(xI+xRun)@(yI+yRun) putValue:aPixelValueOrNil.
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9901
            ].
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9902
        ].
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9903
    ].
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9904
    tempForm destroy.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9905
    tempImage close.
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9906
    self release. "/ device-image is no longer valid
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9907
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9908
    "
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9909
     |cm i|
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9910
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9911
     cm :=  Array with:Color white with:Color black with:Color red.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9912
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9913
     i := Depth8Image extent:300@400 depth:8 palette:cm.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9914
     i fillEllipse:(0@0 corner:80@100) withColor:Color red.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9915
     i inspect.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9916
    "
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9917
!
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9918
4995
3a5cb7a57b0b changed #fillRectangle:aRectangle withColor:aColor
sr
parents: 4994
diff changeset
  9919
fillRectangle:aRectangle withColor:aColor
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9920
    self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9921
        fillRectangle:aRectangle
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9922
        withValue:(self valueFromColor:aColor)
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9923
!
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9924
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9925
fillRectangle:aRectangle withValue:aPixelValueOrNil
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9926
    "fill a rectangular area with some pixel value.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9927
     May be redefined in concrete subclasses for more performance, if req'd.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9928
     If aPixelValueOrNil is nil, the mask pixel will be set to 0 (transparent),
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9929
     otherwise to 1. (used by the bitmap editor)"
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9930
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9931
    self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9932
        fillRectangleX:aRectangle left y:aRectangle top
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9933
        width:aRectangle width height:aRectangle height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9934
        withValue:aPixelValueOrNil
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9935
!
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9936
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9937
fillRectangleX:x y:y width:w height:h with:aColor
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9938
    "fill a rectangular area with a aColor"
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9939
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9940
    self fillRectangleX:x y:y width:w height:h withValue:(self valueFromColor:aColor)
1630
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  9941
!
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  9942
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9943
fillRectangleX:x y:y width:w height:h withValue:aPixelValueOrNil
1630
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  9944
    "fill a rectangular area with some pixel value.
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9945
     May be redefined in concrete subclasses for more performance, if req'd.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9946
     If aPixelValueOrNil is nil, the mask pixel will be set to 0 (transparent),
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9947
     otherwise to 1. (used by the bitmap editor)"
1630
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  9948
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  9949
    |xI "{ Class: SmallInteger }"
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9950
     yI "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9951
     wI "{ Class: SmallInteger }"
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9952
     hI "{ Class: SmallInteger }"
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9953
     p|
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9954
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9955
    xI := x.
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9956
    yI := y.
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9957
    wI := w.
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9958
    hI := h.
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9959
    p := Point new.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9960
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9961
    yI to:yI+hI-1 do:[:yRun |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9962
        xI to:xI+wI-1 do:[:xRun |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9963
            p x:xRun y:yRun.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9964
            self atImageAndMask:p putValue:aPixelValueOrNil.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9965
        ]
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9966
    ].
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9967
    self release. "/ device-image is no longer valid
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9968
1630
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  9969
    "Created: 22.4.1997 / 14:02:14 / cg"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9970
    "Modified: 24.4.1997 / 17:24:58 / cg"
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9971
!
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9973
floodFillAt: aPoint withColor: aColor
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9974
    "fill a area with aColor like a flood up to surrounded pixels having different colors.
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9975
     By using #atImageAndMask:put: it also works on images with mono masks."
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9976
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9977
    self floodFillAt:aPoint withValue:(self valueFromColor:aColor)
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9978
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9979
"/    |surroundingPixelsOfDo detectedPixel processPixelToFill
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9980
"/     allDetectedPixelCoordinates enumerateDetectedPixelsAndDo
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9981
"/     toDo idx pixel w h|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9982
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9983
"/    w := self width.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9984
"/    h := self height.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9985
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9986
"/    surroundingPixelsOfDo :=
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9987
"/        [:pX :pY :fn |
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9988
"/            |nX nY|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9989
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9990
"/            nX := pX + 1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9991
"/            nY := pY + 1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9992
"/            (nY < h) ifTrue: [fn value:pX value:nY].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9993
"/            (pY > 0) ifTrue: [fn value:pX value:(pY - 1)].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9994
"/            (nX < w) ifTrue: [fn value:nX value:pY].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9995
"/            (pX > 0) ifTrue: [fn value:(pX - 1) value:pY].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9996
"/        ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9997
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9998
"/    enumerateDetectedPixelsAndDo :=
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9999
"/        [:detectedPixels :action |
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10000
"/            |idx|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10001
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10002
"/            idx := 1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10003
"/            0 to:h-1 do:[:y |
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10004
"/                0 to:w-1 do:[:x |
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10005
"/                    (detectedPixels at:idx) ifTrue:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10006
"/                        action value:x value:y
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10007
"/                    ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10008
"/                    idx := idx + 1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10009
"/                ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10010
"/            ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10011
"/        ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10012
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10013
"/    processPixelToFill := [:spX :spY |
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10014
"/            |sp idx|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10015
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10016
"/            ((self pixelAtX:spX y:spY) == detectedPixel and: [mask isNil or:[(mask pixelAtX:spX y:spY) == 1]])
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10017
"/            ifTrue: [
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10018
"/                idx := 1 + spX + (spY * w).
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10019
"/                (allDetectedPixelCoordinates at:idx) ifFalse:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10020
"/                    allDetectedPixelCoordinates at:idx put:true.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10021
"/                    toDo add:spX @ spY.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10022
"/                ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10023
"/            ]
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10024
"/        ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10025
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10026
"/    (mask notNil and: [(mask pixelAt:aPoint) == 0]) ifTrue:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10027
"/        allDetectedPixelCoordinates := mask floodFillAt: aPoint withColor: Color white.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10028
"/        enumerateDetectedPixelsAndDo
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10029
"/                value:allDetectedPixelCoordinates
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10030
"/                value:[:x :y | self atImageAndMask:(x@y) put: aColor].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10031
"/        ^ allDetectedPixelCoordinates
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10032
"/    ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10033
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10034
"/    detectedPixel := self pixelAt: aPoint.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10035
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10036
"/    allDetectedPixelCoordinates := BooleanArray new:(w * h).
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10037
"/    toDo := OrderedCollection new:1000.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10038
"/    allDetectedPixelCoordinates at:(1 + aPoint x + (aPoint y * w)) put:true.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10039
"/    toDo add:aPoint.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10040
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10041
"/    [toDo notEmpty] whileTrue:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10042
"/        |p|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10043
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10044
"/        p := toDo removeFirst.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10045
"/        surroundingPixelsOfDo value:p x value:p y value:processPixelToFill.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10046
"/    ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10047
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10048
"/    idx := 1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10049
"/    aColor redByte notNil ifTrue:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10050
"/        pixel := self valueFromColor:aColor.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10051
"/    ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10052
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10053
"/    pixel isNil ifTrue:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10054
"/        enumerateDetectedPixelsAndDo
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10055
"/                value:allDetectedPixelCoordinates
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10056
"/                value:[:x :y | mask pixelAtX:x y:y put:0].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10057
"/    ] ifFalse:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10058
"/        enumerateDetectedPixelsAndDo
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10059
"/                value:allDetectedPixelCoordinates
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10060
"/                value:[:x :y | self pixelAtX:x y:y put:pixel].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10061
"/    ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10062
"/    ^ allDetectedPixelCoordinates
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10063
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10064
    "Modified: / 29.7.1998 / 03:09:16 / cg"
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10065
!
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10066
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10067
floodFillAt:aPoint withValue:aPixelValueOrNil
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10068
    "fill a area with aColor like a flood up to surrounded pixels having different colors.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10069
     By using #atImageAndMask:put: it also works on images with mono masks."
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10070
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10071
    |surroundingPixelsOfDo detectedPixel detectedMask processPixelToFill
3861
e9cbd4ec6020 flood fill with mask fixed
Claus Gittinger <cg@exept.de>
parents: 3860
diff changeset
 10072
     allDetectedPixelCoordinates enumerateDetectedPixelsAndDo
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10073
     toDo w h drawAction|
2205
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
 10074
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
 10075
    w := self width.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
 10076
    h := self height.
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
 10077
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10078
    surroundingPixelsOfDo :=
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10079
        [:pX :pY :fn |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10080
            |nX nY|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10081
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10082
            nX := pX + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10083
            nY := pY + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10084
            (nY < h) ifTrue: [fn value:pX value:nY].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10085
            (pY > 0) ifTrue: [fn value:pX value:(pY - 1)].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10086
            (nX < w) ifTrue: [fn value:nX value:pY].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10087
            (pX > 0) ifTrue: [fn value:(pX - 1) value:pY].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10088
        ].
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10089
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10090
    enumerateDetectedPixelsAndDo :=
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10091
        [:detectedPixels :action |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10092
            |idx|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10093
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10094
            idx := 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10095
            0 to:h-1 do:[:y |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10096
                0 to:w-1 do:[:x |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10097
                    (detectedPixels at:idx) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10098
                        action value:x value:y
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10099
                    ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10100
                    idx := idx + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10101
                ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10102
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10103
        ].
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10104
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10105
    processPixelToFill :=
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10106
        [:spX :spY |
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 10107
            |samePixel idx|
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10108
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10109
            mask isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10110
                samePixel := (self pixelAtX:spX y:spY) == detectedPixel
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10111
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10112
                detectedMask == 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10113
                    samePixel := (mask pixelAtX:spX y:spY) == 0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10114
                ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10115
                    samePixel := ((self pixelAtX:spX y:spY) == detectedPixel)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10116
                                 and:[ (mask pixelAtX:spX y:spY) == detectedMask ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10117
                ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10118
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10119
            samePixel ifTrue: [
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10120
                idx := 1 + spX + (spY * w).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10121
                (allDetectedPixelCoordinates at:idx) ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10122
                    allDetectedPixelCoordinates at:idx put:true.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10123
                    toDo add:spX @ spY.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10124
                ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10125
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10126
        ].
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10127
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10128
"/    (mask notNil and: [(mask pixelAt:aPoint) == 0]) ifTrue:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10129
"/        allDetectedPixelCoordinates := mask floodFillAt: aPoint withColor: Color white.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10130
"/        enumerateDetectedPixelsAndDo
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10131
"/                value:allDetectedPixelCoordinates
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10132
"/                value:[:x :y | self atImageAndMask:(x@y) putValue:aPixelValueOrNil].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10133
"/        ^ allDetectedPixelCoordinates
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10134
"/    ].
3759
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
 10135
2205
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
 10136
    detectedPixel := self pixelAt: aPoint.
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10137
    mask isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10138
        detectedMask := 1
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10139
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10140
        detectedMask := mask pixelAt: aPoint.
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10141
    ].
4420
6b8505b72ae6 flood-filling of 24-bit images
Claus Gittinger <cg@exept.de>
parents: 4418
diff changeset
 10142
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10143
    allDetectedPixelCoordinates := BooleanArray new:(w * h).
3759
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
 10144
    toDo := OrderedCollection new:1000.
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10145
    allDetectedPixelCoordinates at:((aPoint y * w) + aPoint x + 1) put:true.
3759
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
 10146
    toDo add:aPoint.
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
 10147
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
 10148
    [toDo notEmpty] whileTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10149
        |p|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10150
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10151
        p := toDo removeLast.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10152
        surroundingPixelsOfDo value:p x value:p y value:processPixelToFill.
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10153
    ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10154
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10155
    aPixelValueOrNil isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10156
        drawAction := [:x :y |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10157
                               mask pixelAtX:x y:y put:0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10158
                               self pixelAtX:x y:y put:0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10159
                      ].
3805
d87c919fb2a7 oops - care for filling a mask
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
 10160
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10161
        drawAction := [:x :y |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10162
                                mask notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10163
                                    mask pixelAtX:x y:y put:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10164
                                ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10165
                                self pixelAtX:x y:y put:aPixelValueOrNil].
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10166
    ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10167
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10168
    enumerateDetectedPixelsAndDo
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10169
        value:allDetectedPixelCoordinates
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10170
        value:drawAction.
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10171
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
 10172
    self release. "/ device-image is no longer valid
3805
d87c919fb2a7 oops - care for filling a mask
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
 10173
    ^ allDetectedPixelCoordinates
2205
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
 10174
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 10175
    "Modified: / 29-07-1998 / 03:09:16 / cg"
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 10176
    "Modified (format): / 30-01-2017 / 20:57:36 / stefan"
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
 10177
!
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
 10178
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
 10179
rectangle: aRectangle withColor:aColor
5216
f7ec910cfce1 Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 5200
diff changeset
 10180
    <resource: #obsolete>
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
 10181
    "draw a rectangle with some pixel value.
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
 10182
    By using #atImageAndMask:put: it also works on images with mono masks."
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
 10183
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
 10184
    self obsoleteMethodWarning.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
 10185
    self drawRectangle: aRectangle withColor:aColor
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
 10186
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
 10187
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 10188
! !
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 10189
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10190
!Image methodsFor:'enumerating'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10191
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10192
atY:y from:x1 to:x2 do:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10193
    "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
 10194
     The block is passed the color at each pixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10195
     The code here provides a generic and slow implementation, and
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10196
     should be redefined in concrete subclasses, to avoid some processing
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10197
     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
 10198
     and also the color allocation)."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10199
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
 10200
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
 10201
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10202
    self obsoleteMethodWarning:'use #colorsAtY:from:to:do:'.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10203
    self colorsAtY:y from:x1 to:x2 do:aBlock
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10204
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10205
    "Modified: 7.6.1996 / 19:13:30 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10206
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10207
5143
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
 10208
colorsAtX:x from:y1 to:y2 do:aBlock
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
 10209
    "perform aBlock for each pixel from y1 to y2 in col x.
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
 10210
     The block is passed the color at each pixel.
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
 10211
     The code here provides a generic and slow implementation, and
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
 10212
     should be redefined in concrete subclasses, to avoid some processing
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
 10213
     when going from pixel to pixel (i.e. the byte-index and mask computations
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
 10214
     and also the color allocation)."
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
 10215
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
 10216
    |yStart "{Class: SmallInteger }"
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
 10217
     yEnd   "{Class: SmallInteger }"|
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
 10218
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
 10219
    yStart := y1.
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
 10220
    yEnd := y2.
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
 10221
    yStart to:yEnd do:[:yRun |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10222
        aBlock value:yRun value:(self colorAtX:x y:yRun)
5143
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
 10223
    ]
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
 10224
!
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
 10225
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10226
colorsAtY:y from:x1 to:x2 do:aBlock
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10227
    "perform aBlock for each pixel from x1 to x2 in row y.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10228
     The block is passed the color at each pixel.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10229
     The code here provides a generic and slow implementation, and
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10230
     should be redefined in concrete subclasses, to avoid some processing
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10231
     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
 10232
     and also the color allocation)."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10233
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10234
    |xStart "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10235
     xEnd   "{Class: SmallInteger }"|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10236
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10237
    xStart := x1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10238
    xEnd := x2.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10239
    xStart to:xEnd do:[:xRun |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10240
        aBlock value:xRun value:(self colorAtX:xRun y:y)
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10241
    ]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10242
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
 10243
    "Created: / 7.6.1996 / 19:12:51 / cg"
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
 10244
    "Modified: / 30.9.1998 / 22:14:16 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10245
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10246
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10247
colorsFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10248
    "perform aBlock for each color in a rectangular area of the image.
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 10249
     Notice that x and y coordinates start at 0@0 for the upper left corner.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10250
     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
 10251
     The code here provides a generic and slow implementation, and
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10252
     should be redefined in concrete subclasses, to avoid some processing
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10253
     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
 10254
     and especially, the color allocations)."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10255
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 10256
    |yS "{Class: SmallInteger }"
7595
c77d718d3d94 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7573
diff changeset
 10257
     yE "{Class: SmallInteger }"|
942
5e45da3c19d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
 10258
5e45da3c19d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
 10259
    yS := yStart.
5e45da3c19d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
 10260
    yE := yEnd.
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 10261
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10262
    yS to:yE do:[:yRun |
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 10263
        self colorsAtY:yRun from:xStart to:xEnd do:[:xRun :color |
7595
c77d718d3d94 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7573
diff changeset
 10264
            aBlock value:xRun value:yRun value:color
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 10265
        ]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10266
    ]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10267
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 10268
    "Modified: 11.7.1996 / 19:50:47 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10269
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10270
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10271
valueAtY:y from:x1 to:x2 do:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10272
    "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
 10273
     Obsolete - remains for backward compatibility."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10274
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
 10275
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
 10276
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10277
    self obsoleteMethodWarning:'use #valuesAtY:from:to:do:'.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10278
    self valuesAtY:y from:x1 to:x2 do:aBlock
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10279
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10280
    "Modified: 7.6.1996 / 19:11:06 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10281
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10282
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10283
valuesAtY:y from:x1 to:x2 do:aBlock
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10284
    "WARNING: for now, this enumerates pixel values
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10285
     (backward compatibility with ST/X)
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10286
     In the future, this will enumerate colors
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10287
     Use #pixelAtT:from:to:do: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10288
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10289
     perform aBlock for each pixelValue from x1 to x2 in row y.
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 10290
     Notice that x and y coordinates start at 0@0 for the upper left corner.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10291
     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
 10292
     (see also Image>>atY:from:to:do:).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10293
     The code here provides a generic and slow implementation, and
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10294
     should be redefined in concrete subclasses, to avoid some processing
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10295
     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
 10296
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10297
    |xStart "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10298
     xEnd   "{Class: SmallInteger }"|
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
    xStart := x1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10301
    xEnd := x2.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10302
    xStart to:xEnd do:[:xRun |
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 10303
        aBlock value:xRun value:(self pixelAtX:xRun y:y)
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10304
    ]
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10305
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10306
    "Created: 7.6.1996 / 19:09:51 / cg"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10307
    "Modified: 24.4.1997 / 16:55:38 / cg"
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
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10310
valuesFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10311
    "perform aBlock for each pixelValue in a rectangular area of the image.
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 10312
     Notice that x and y coordinates start at 0@0 for the upper left corner.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10313
     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
 10314
     The code here provides a generic and slow implementation, and
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10315
     should be redefined in concrete subclasses, to avoid some processing
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10316
     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
 10317
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 10318
    |yS "{Class: SmallInteger }"
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 10319
     yE "{Class: SmallInteger }"|
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 10320
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 10321
    yS := yStart.
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 10322
    yE := yEnd.
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 10323
    yS to:yE do:[:yRun |
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 10324
        self valuesAtY:yRun from:xStart to:xEnd do:[:xRun :pixel |
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 10325
            aBlock value:xRun value:yRun value:pixel
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 10326
        ]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10327
    ]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10328
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 10329
    "Modified: / 07-06-1996 / 19:09:29 / cg"
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 10330
    "Modified: / 31-01-2017 / 14:46:26 / stefan"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 10331
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
 10332
3613
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10333
!Image methodsFor:'finalization'!
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10334
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10335
finalizationLobby
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10336
    "answer the registry used for finalization.
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10337
     Images have their own Registry"
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10338
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10339
    ^ Lobby
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10340
!
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10341
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10342
finalize
7483
0690072b1c56 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 7482
diff changeset
 10343
    "some Image has been collected - nothing to do.
0690072b1c56 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 7482
diff changeset
 10344
0690072b1c56 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 7482
diff changeset
 10345
     The only reason we register Images is, that we can release
0690072b1c56 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 7482
diff changeset
 10346
     their device resources when a GraphicsDevice is closed.
0690072b1c56 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 7482
diff changeset
 10347
0690072b1c56 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 7482
diff changeset
 10348
     (#releaseResourcesOnDevice: at class side)."
3613
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10349
! !
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10350
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 10351
!Image methodsFor:'image manipulations'!
48194c26a46c Initial revision
claus
parents:
diff changeset
 10352
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10353
applyPixelValuesTo:pixelFunctionBlock in:aRectangle into:newImage
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 10354
    "helper for withPixelFunctionAppliedToValues:
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 10355
     enumerate pixelValues and evaluate the block for each.
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10356
     Could be redefined by subclasses for better performance."
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10357
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10358
    |w   "{Class: SmallInteger }"
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10359
     h   "{Class: SmallInteger }"
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10360
     x0  "{Class: SmallInteger }"
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10361
     y0  "{Class: SmallInteger }"
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10362
     y   "{Class: SmallInteger }"
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10363
     newPixel newPixelRow pixelRow|
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10364
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10365
    x0 := aRectangle left.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10366
    y0 := aRectangle top.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10367
    w := aRectangle width.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10368
    h := aRectangle height.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10369
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10370
    newPixelRow := Array new:w.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10371
    pixelRow := self pixelArraySpecies new:width.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10372
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10373
    (x0 = 0 and:[w = self width]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10374
        "/ slightly faster
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10375
        y := y0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10376
        h timesRepeat:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10377
            self rowAt:y into:pixelRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10378
            1 to:w do:[:runCol |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10379
                newPixel := pixelFunctionBlock
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10380
                                value:self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10381
                                value:(pixelRow at:runCol)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10382
                                value:(runCol-1)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10383
                                value:y.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10384
                newPixelRow at:runCol put:newPixel.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10385
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10386
            newImage rowAt:y putAll:newPixelRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10387
            y := y + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10388
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10389
        ^ self.
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10390
    ].
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10391
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10392
    y := y0.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10393
    h timesRepeat:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10394
        self rowAt:y into:pixelRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10395
        1 to:w do:[:runCol |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10396
            newPixel := pixelFunctionBlock
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10397
                            value:self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10398
                            value:(pixelRow at:runCol+x0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10399
                            value:(runCol+x0-1)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10400
                            value:y.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10401
            newPixelRow at:runCol put:newPixel.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10402
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10403
        pixelRow replaceFrom:x0+1 to:x0+1+w-1 with:newPixelRow startingAt:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10404
        newImage rowAt:y putAll:pixelRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10405
        y := y + 1.
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10406
    ].
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10407
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10408
    "Modified: 24.4.1997 / 16:18:31 / cg"
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10409
!
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10410
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10411
applyPixelValuesTo:pixelFunctionBlock into:newImage
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10412
    "helper for withPixelFunctionAppliedToValues:
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10413
     enumerate pixelValues and evaluate the block for each."
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10414
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10415
    ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10416
        applyPixelValuesTo:pixelFunctionBlock
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10417
        in:(0@0 corner:width@height)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10418
        into:newImage
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10419
!
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10420
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10421
blendWith:aColor
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10422
    "return a new image which is blended with some color.
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10423
     The receiver must be a palette image (currently).
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10424
     CAVEAT: this only works with palette images (i.e. not for rgb or greyScale).
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10425
     CAVEAT: Need an argument, which specifies by how much it should be lighter."
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10426
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10427
     ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10428
        copyWithColorMapProcessing:[:clr | clr blendWith:aColor]
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10429
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10430
    "
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10431
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10432
     ((Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') blendWith:Color red) inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10433
     ((Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') blendWith:Color white) inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10434
     ((Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') blendWith:Color black) inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10435
    "
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10436
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10437
    "Modified: 24.4.1997 / 18:31:23 / cg"
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10438
!
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10439
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10440
colorMapProcessing:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10441
    "a helper for all kinds of colormap manipulations.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10442
     The argument, aBlock is called for every colormap entry,
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10443
     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
 10444
     This will fail for non-palette images.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10445
     See examples in Image>>copyWithColorMapProcessing:"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10446
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10447
    |nColors "{ Class: SmallInteger }"|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10448
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10449
    colorMap isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10450
        self colorsFromX:0 y:0 toX:(self width-1) y:(self height-1) do:[:x :y :clr |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10451
            self colorAtX:x y:y put:(aBlock value:clr)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10452
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10453
        ^ self
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10454
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10455
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10456
    nColors := colorMap size.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10457
    1 to:nColors do:[:index |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10458
        |clr|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10459
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10460
        clr := colorMap at:index.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10461
        clr notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10462
            colorMap at:index put:(aBlock value:clr)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10463
        ]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10464
    ]
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10465
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10466
    "Modified: 23.4.1996 / 11:13:55 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10467
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10468
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10469
copyWithColorMapProcessing:aBlock
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10470
    "a helper to create & return new images based on the receiver with
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10471
     some colorMap processing. The receiver is copied, and the copied images
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10472
     colormap is modified by replacing entries with the result of the processing block,
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10473
     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
 10474
     a color.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10475
     CAVEAT: this only works with palette images (i.e. not for rgb or greyScale)"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10476
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10477
    |newImage|
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10478
4414
2c0f2ca53156 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
 10479
    self colorMap isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10480
        ^ self withPixelFunctionApplied:[:orig :clr :x :y | aBlock  value:clr]
4414
2c0f2ca53156 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
 10481
"/        self error:'no colormap in image'.
2c0f2ca53156 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
 10482
"/        ^ nil
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10483
    ].
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10484
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10485
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10486
     the code below manipulates the colormap.
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10487
     For non-palette images, special code is required
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10488
    "
4414
2c0f2ca53156 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
 10489
    newImage := self copy.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10490
    newImage colorMapProcessing:aBlock.
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10491
    ^ newImage
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10492
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10493
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10494
     leave red component only:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10495
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10496
     (Image fromFile:'goodies/bitmaps/gifImages/claus.gif')
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10497
        copyWithColorMapProcessing:[:clr | Color red:(clr red) green:0 blue:0]
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10498
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10499
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10500
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10501
     make it reddish:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10502
6653
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10503
     |img imgYellow imgGreen imgBlue|
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10504
     img := (Image fromFile:'../../../expeccoNET/server/data/images/styles/eXept/defects.gif').
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10505
     imgYellow := img copyWithColorMapProcessing:[:clr | Color hue:(clr hue ? 0 + 60) light:clr light saturation:clr saturation].
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10506
     imgGreen := img copyWithColorMapProcessing:[:clr | Color hue:(clr hue ? 0 + 120) light:clr light saturation:clr saturation].
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10507
     imgBlue := img copyWithColorMapProcessing:[:clr | Color hue:(clr hue ? 0 + 240) light:clr light saturation:clr saturation].
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10508
     imgBlue
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10509
    "
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10510
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10511
    "
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10512
     make it reddish:
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10513
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10514
     (Image fromFile:'../../goodies/bitmaps/gifImages/claus.gif')
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10515
        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
 10516
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10517
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10518
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10519
     invert:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10520
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10521
     (Image fromFile:'bitmaps/gifImages/claus.gif')
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10522
        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
 10523
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10524
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10525
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10526
     lighter:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10527
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10528
     (Image fromFile:'bitmaps/gifImages/claus.gif')
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10529
        copyWithColorMapProcessing:[:clr | |r g b|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10530
                                                r := clr red.  g := clr green.  b := clr blue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10531
                                                Color red:(r + (100-r//2))
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10532
                                                      green:(g + (100-g//2))
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10533
                                                      blue:(b + (100-b//2))]
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10534
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10535
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10536
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10537
     darker:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10538
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10539
     (Image fromFile:'bitmaps/gifImages/claus.gif')
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10540
        copyWithColorMapProcessing:[:clr | Color red:(clr red//2) green:(clr green // 2) blue:(clr blue // 2)]
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10541
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10542
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10543
    "Modified: 24.4.1997 / 18:28:05 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10544
!
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10545
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10546
createMask
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10547
    |maskArray bytesPerMaskRow|
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10548
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10549
    bytesPerMaskRow := (width+7) // 8.
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10550
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10551
    maskArray := ByteArray new:(bytesPerMaskRow * height) withAll:2r11111111.
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10552
    mask := ImageMask width:width height:height fromArray:maskArray.
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10553
    ^ mask
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10554
!
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10555
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10556
darkened
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10557
    "return a new image which is slightly darker than the receiver.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10558
     The receiver must be a palette image (currently).
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10559
     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
 10560
     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
 10561
5655
37bd5c7eb765 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 5643
diff changeset
 10562
     ^ self copyWithColorMapProcessing:[:clr | clr darkened]
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10563
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10564
    "
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10565
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10566
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') darkened inspect
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10567
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10568
5655
37bd5c7eb765 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 5643
diff changeset
 10569
    "Modified: / 24-11-2010 / 11:06:58 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10570
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10571
7534
0b7e23635791 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7529
diff changeset
 10572
easyRotateBitsInto:destinationImage angle:degrees
7523
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10573
    "helper for rotation - does the actual pixel shuffling.
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10574
     by degrees clockwise. Here, only 90, 180 and 270 degrees
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10575
     are implemented. Hard angles are done in #hardRotate:.
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10576
     The code here is depth-independent (but not too fast);
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10577
     can be redefined in subclasses for more performance"
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10578
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10579
    |w  "{Class: SmallInteger }"
7529
5f77a718b7bd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7523
diff changeset
 10580
     h  "{Class: SmallInteger }" 
5f77a718b7bd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7523
diff changeset
 10581
     pixelMover|
7523
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10582
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10583
    w := width - 1.
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10584
    h := height - 1.
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10585
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10586
    degrees = 90 ifTrue:[
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10587
        pixelMover := [:col :row :pixel | destinationImage pixelAtX:(h-row) y:col put:pixel].    
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10588
    ] ifFalse:[
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10589
        degrees = 180 ifTrue:[
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10590
            pixelMover := [:col :row :pixel | destinationImage pixelAtX:(w-col) y:(h-row) put:pixel].    
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10591
        ] ifFalse:[
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10592
            degrees = 270 ifTrue:[
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10593
                pixelMover := [:col :row :pixel | destinationImage pixelAtX:row y:(w-col) put:pixel].    
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10594
            ] ifFalse:[
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10595
                ^ self
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10596
            ].
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10597
        ].
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10598
    ].    
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10599
    self valuesFromX:0 y:0 toX:w y:h do:pixelMover.
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10600
    ^ self.
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10601
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10602
    "
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10603
     |i|
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10604
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10605
     i := Image fromFile:'../../goodies/bitmaps/gifImages/claus.gif'.
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10606
     i inspect.
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10607
     (i rotated:45) inspect.
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10608
     (i rotated:90) inspect.
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10609
     (i rotated:180) inspect.
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10610
     (i rotated:270) inspect.
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10611
    "
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10612
    "
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10613
     |i|
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10614
     i := Image fromFile:'../../goodies/bitmaps/gifImages/claus.gif'.
7529
5f77a718b7bd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7523
diff changeset
 10615
     i := Depth24Image fromImage:i.
7523
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10616
     Time millisecondsToRun:[ 100 timesRepeat:[ i rotated:90 ] ]
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10617
    "
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10618
    "
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10619
     |i|
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10620
     i := Image fromScreen.
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10621
     Time millisecondsToRun:[ 20 timesRepeat:[ i rotated:90 ] ]
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10622
    "
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10623
    
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10624
    "Created: 23.4.1997 / 14:36:45 / cg"
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10625
    "Modified: 24.4.1997 / 17:26:26 / cg"
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10626
!
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10627
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10628
flipHorizontal
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10629
    "destructively inplace horizontal flip"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10630
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10631
    |h  "{Class: SmallInteger }"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10632
     pixelArray|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10633
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10634
    h := height - 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10635
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10636
    pixelArray := self pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10637
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10638
    0 to:h do:[:row |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10639
        self rowAt:row into:pixelArray.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10640
        pixelArray reverse.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10641
        self rowAt:row putAll:pixelArray.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10642
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10643
1386
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
 10644
    mask notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10645
        mask flipHorizontal
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10646
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10647
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10648
    "/ flush device info
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 10649
    self release
1386
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
 10650
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10651
    "
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10652
     (Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') flipHorizontal inspect
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10653
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10654
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10655
    "Modified: 24.4.1997 / 18:29:13 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10656
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10657
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10658
flipVertical
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10659
    "inplace vertical flip"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10660
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10661
    |h           "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10662
     bytesPerRow "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10663
     buffer
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10664
     indexLow    "{Class: SmallInteger }"
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 10665
     indexHi     "{Class: SmallInteger }"
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 10666
     bytes|
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 10667
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 10668
    bytes := self bits.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10669
    bytesPerRow := self bytesPerRow.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10670
    buffer := ByteArray new:bytesPerRow.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10671
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10672
    h := height - 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10673
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10674
    indexLow := 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10675
    indexHi := bytesPerRow * h + 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10676
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10677
    0 to:(h // 2) do:[:row |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10678
        buffer replaceFrom:1 to:bytesPerRow with:bytes startingAt:indexLow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10679
        bytes replaceFrom:indexLow to:(indexLow + bytesPerRow - 1) with:bytes startingAt:indexHi.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10680
        bytes replaceFrom:indexHi to:(indexHi + bytesPerRow - 1) with:buffer startingAt:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10681
        indexLow := indexLow + bytesPerRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10682
        indexHi := indexHi - bytesPerRow.
1386
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
 10683
    ].
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
 10684
    mask notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10685
        mask flipVertical
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10686
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10687
    "flush device info"
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 10688
    self release
1386
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
 10689
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10690
    "
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10691
     (Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') flipVertical inspect
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10692
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10693
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10694
    "Modified: 24.4.1997 / 18:29:36 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10695
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10696
1739
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10697
hardAntiAliasedMagnifiedBy:scalePoint
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10698
    "return a new image magnified and antiAliased by scalePoint, aPoint.
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10699
     This converts into a depth24Image before doing the antiAlias-magnify.
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10700
     It is definitely slower than the non antiAliasing/integral magnification methods."
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10701
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10702
    ^ (Depth24Image fromImage:self)
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10703
        hardAntiAliasedMagnifiedBy:scalePoint
1739
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10704
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10705
    "Modified: 2.6.1997 / 13:19:57 / cg"
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10706
    "Created: 2.6.1997 / 15:53:34 / cg"
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10707
!
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10708
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10709
hardMagnifiedBy:scalePoint
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10710
    "return a new image magnified by scalePoint, aPoint.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10711
     This is the general magnification method, handling non-integral values.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10712
     It is slower than the integral magnification method."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10713
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10714
    |mX
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10715
     mY
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10716
     newWidth  "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10717
     newHeight "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10718
     w         "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10719
     h         "{ Class: SmallInteger }"
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 10720
     newImage newBits bitsPerPixel newBytesPerRow newMask
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10721
     value
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10722
     srcRow pixelArray|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10723
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10724
    mX := scalePoint x.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10725
    mY := scalePoint y.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10726
    ((mX < 0) or:[mY < 0]) ifTrue:[^ nil].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10727
    ((mX = 1) and:[mY = 1]) ifTrue:[^ self].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10728
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10729
    newWidth := (width * mX) truncated.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10730
    newHeight := (height * mY) truncated.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10731
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10732
    bitsPerPixel := self depth.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10733
    newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10734
    newBits := ByteArray uninitializedNew:(newBytesPerRow * newHeight).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10735
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 10736
    mask notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10737
        newMask := (mask magnifiedBy:scalePoint)
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 10738
    ].
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 10739
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10740
    newImage := self species new.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10741
    newImage
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10742
        width:newWidth
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10743
        height:newHeight
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10744
        photometric:photometric
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10745
        samplesPerPixel:samplesPerPixel
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10746
        bitsPerSample:bitsPerSample
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10747
        colorMap:colorMap copy
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10748
        bits:newBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10749
        mask:newMask.
905
228d503775d9 everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents: 904
diff changeset
 10750
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10751
    "walk over destination image fetching pixels from source image"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10752
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10753
    w := newWidth - 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10754
    h := newHeight - 1.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10755
    pixelArray := newImage pixelArraySpecies new:newWidth.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10756
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10757
    0 to:h do:[:row |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10758
        srcRow := (row // mY).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10759
        0 to:w do:[:col |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10760
            value := self pixelAtX:(col // mX) y:srcRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10761
            pixelArray at:(col+1) put:value.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10762
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10763
        newImage rowAt:row putAll:pixelArray.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10764
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10765
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10766
    ^ newImage
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10767
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10768
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10769
     |i|
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10770
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10771
     Time millisecondsToRun:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10772
         i := i hardMagnifiedBy:0.5@0.5
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10773
     ].
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10774
     i
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10775
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10776
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10777
    "Modified: 24.4.1997 / 18:30:24 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10778
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10779
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10780
hardRotated:degrees
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10781
    "return a new image from the old one, by rotating the image
4953
b5017336aa26 comment
Claus Gittinger <cg@exept.de>
parents: 4952
diff changeset
 10782
     degrees clockwise (around its center).
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10783
     Warning: the returned image will be larger than the original image."
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10784
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10785
    |p r a aN p1 p2 p3 p4 maxX minX maxY minY
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10786
     newImage
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10787
     newWidth  "{ Class: SmallInteger }"
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10788
     newHeight "{ Class: SmallInteger }"
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10789
     newBytesPerRow newBits
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10790
     blackPixel halfW halfH radians m t bad
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10791
     bytesPerRow myDepth maskBits
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10792
     pX pY srcX srcY pix nX nY
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10793
     sinRot cosRot sinPY cosPY|
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10794
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 10795
    radians := degrees degreesToRadians.
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 10796
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10797
    "/ placing the image at the origin,
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10798
    "/ compute the diagonal and angle.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10799
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10800
    p := (width - 1 / 2) @ (height - 1 / 2).
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10801
    r := p r.
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 10802
    a := p theta.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10803
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10804
    "/ add the rotation
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10805
    "/ (sight - subtract, we defined things clockwise ...
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10806
    "/  ... in contrast to point which thinks counter-clockwise)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10807
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 10808
    aN := a - radians.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10809
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10810
    "/ compute new corner points
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 10811
    p1 := Point r:r theta:aN.         "/ rotated topRight
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 10812
    p2 := Point r:r theta:aN-a-a.     "/ rotated bottomRight
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10813
    p3 := p1 * -1.                    "/ rotated bottomLeft
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10814
    p4 := p2 * -1.                    "/ rotated topLeft
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10815
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10816
    "/ compute the boundary of the new image
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10817
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10818
    maxX := minX := p1 x.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10819
    (t := p2 x) > maxX ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10820
        maxX := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10821
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10822
        t < minX ifTrue:[minX := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10823
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10824
    (t := p3 x) > maxX ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10825
        maxX := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10826
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10827
        t < minX ifTrue:[minX := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10828
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10829
    (t := p4 x) > maxX ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10830
        maxX := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10831
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10832
        t < minX ifTrue:[minX := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10833
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10834
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10835
    maxY := minY := p1 y.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10836
    (t := p2 y) > maxY ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10837
        maxY := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10838
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10839
        t < minY ifTrue:[minY := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10840
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10841
    (t := p3 y) > maxY ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10842
        maxY := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10843
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10844
        t < minY ifTrue:[minY := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10845
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10846
    (t := p4 y) > maxY ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10847
        maxY := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10848
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10849
        t < minY ifTrue:[minY := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10850
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10851
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10852
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10853
    newWidth := (maxX - minX) rounded + 1.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10854
    newHeight := (maxY - minY) rounded + 1.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10855
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10856
    newImage := self species new.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10857
    newImage width:newWidth.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10858
    newImage height:newHeight.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10859
    newBytesPerRow := newImage bytesPerRow.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 10860
    newImage createPixelStore.
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 10861
    newBits := newImage bits.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10862
    newImage photometric:photometric.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10863
    newImage samplesPerPixel:samplesPerPixel.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10864
    newImage bitsPerSample:bitsPerSample.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10865
    newImage colorMap:colorMap copy.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10866
    newImage maskedPixelsAre0:maskedPixelsAre0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10867
    mask notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10868
        newImage mask:(mask rotated:degrees)
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10869
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10870
        self isMask ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10871
            self depth ~~ 1 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10872
                m := ImageMask width:width height:height.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10873
                m bits:(maskBits := ByteArray new:(m bytesPerRow * height)).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10874
                maskBits atAllPut:16rFF.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10875
                newImage mask:(m rotated:degrees)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10876
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10877
        ]
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10878
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10879
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10880
    myDepth := self depth.
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10881
    myDepth == 1 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10882
        blackPixel := 0.
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10883
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10884
        maskedPixelsAre0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10885
            blackPixel := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10886
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10887
            blackPixel := self valueFromColor:Color black.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10888
            blackPixel isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10889
                blackPixel := self valueFromColor:Color white.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10890
                blackPixel isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10891
                    blackPixel := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10892
                ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10893
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10894
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10895
        self isMask ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10896
            blackPixel := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10897
        ].
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10898
    ].
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10899
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10900
    newBits atAllPut:0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10901
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10902
    "/ now, walk over destination pixels,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10903
    "/ fetching from source.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10904
    "/ (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
 10905
    "/  in the destination image ...)
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10906
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10907
    halfW := (width - 1) / 2.0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10908
    halfH := (height - 1) / 2.0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10909
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10910
    bytesPerRow := self bytesPerRow.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10911
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10912
%{
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10913
    int __newHeight = __intVal(newHeight);
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10914
    int __newWidth = __intVal(newWidth);
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10915
    int __height = __intVal(__INST(height));
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10916
    int __width = __intVal(__INST(width));
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10917
    double __minX, __minY, __radians;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10918
    double __halfW, __halfH;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10919
    int __dstX, __dstY;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10920
    int __depth = __intVal(myDepth);
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10921
    unsigned char *__srcBytes, *__dstBytes;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10922
    unsigned char *__dstPtr, *__dstRowPtr, *__dstEndPtr;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10923
    int __nSrcBytes, __nDstBytes;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10924
    int __srcBytesPerRow = __intVal(bytesPerRow);
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10925
    int __dstBytesPerRow = __intVal(newBytesPerRow);
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10926
    int __dstMask, __blackPixel;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10927
    double __sin, __cos;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10928
    double sin(), cos();
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10929
#   define Float_PI 3.14159
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10930
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10931
    bad = true;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10932
    if (1
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10933
     && __isFloat(minX)
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10934
     && __isFloat(minY)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10935
     && __isFloat(radians)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10936
     && __isFloat(halfW)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10937
     && __isFloat(halfH)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10938
     && __isByteArray(newBits)
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
 10939
     && __isByteArrayLike(__INST(bytes))) {
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10940
        __srcBytes = __ByteArrayInstPtr(__INST(bytes))->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10941
        __dstBytes = __ByteArrayInstPtr(newBits)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10942
        __nSrcBytes = __byteArraySize(__INST(bytes));
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10943
        __nDstBytes = __byteArraySize(newBits);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10944
        __blackPixel = __intVal(blackPixel);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10945
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10946
        __radians = __floatVal(radians);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10947
        __radians = -__radians; /* sigh: clock-wise */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10948
        __sin = sin(__radians);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10949
        __cos = cos(__radians);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10950
        __minX = __floatVal(minX);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10951
        __minY = __floatVal(minY);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10952
        __halfW = __floatVal(halfW);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10953
        __halfH = __floatVal(halfH);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10954
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10955
        __dstRowPtr = __dstBytes;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10956
        __dstEndPtr = __dstBytes + __nDstBytes;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10957
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10958
#       define EARLY_OUT
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10959
#       define FAST_ADVANCE 5
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10960
#       define FAST_ADVANCE2
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10961
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10962
        switch (__depth) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10963
            case 8:
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10964
                for (__dstY = 0; __dstY < __newHeight; __dstY++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10965
                    double __pY, __sinPY, __cosPY;
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 10966
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10967
                    int didFetchInRow = 0;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10968
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10969
                    __pY = (double)(__dstY + __minY);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10970
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10971
                    __sinPY = __sin * __pY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10972
                    __cosPY = __cos * __pY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10973
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10974
                    __dstPtr = __dstRowPtr;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10975
                    __dstRowPtr += __dstBytesPerRow;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10976
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10977
                    for (__dstX = 0; __dstX < __newWidth; __dstX++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10978
                        double __pX, __nX;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10979
                        unsigned __pix;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10980
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10981
                        /* translate X in destination (center to 0/0) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10982
                        __pX = (double)(__dstX + __minX);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10983
                        /* rotate X */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10984
                        __nX = (__cos * __pX) - __sinPY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10985
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10986
                        /* translate X in source (origin to 0/0) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10987
                        __nX = __nX + __halfW + 0.5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10988
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10989
                        /* inside ? */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10990
                        if (__nX < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10991
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10992
                            if (didFetchInRow) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10993
                                break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10994
                            }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10995
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10996
#ifdef FAST_ADVANCE
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10997
                            if (__blackPixel == 0) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10998
                                do {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10999
                                    /* try advance by FAST_ADVANCE pixels ... */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11000
                                    __dstX += FAST_ADVANCE; __dstPtr += FAST_ADVANCE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11001
                                    if (__dstX >= __newWidth) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11002
                                        break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11003
                                    }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11004
                                    __pX = (double)(__dstX + __minX);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11005
                                    __nX = (__cos * __pX) - __sinPY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11006
                                    __nX = __nX + __halfW + 0.5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11007
                                } while (__nX < 0);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11008
                                __dstX -= FAST_ADVANCE; __dstPtr -= FAST_ADVANCE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11009
                            }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11010
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11011
                            __pix = __blackPixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11012
                        } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11013
                            int __srcX;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11014
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11015
                            __srcX = (int)__nX;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11016
                            /* inside ? */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11017
                            if (__srcX >= __width) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11018
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11019
                                if (didFetchInRow) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11020
                                    break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11021
                                }
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 11022
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11023
#ifdef FAST_ADVANCE2
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11024
                                if (__blackPixel == 0) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11025
                                    do {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11026
                                        /* try advance by FAST_ADVANCE pixels ... */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11027
                                        __dstX += FAST_ADVANCE; __dstPtr += FAST_ADVANCE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11028
                                        if (__dstX >= __newWidth) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11029
                                            break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11030
                                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11031
                                        __pX = (double)(__dstX + __minX);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11032
                                        __nX = (__cos * __pX) - __sinPY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11033
                                        __nX = __nX + __halfW + 0.5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11034
                                        __srcX = (int)__nX;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11035
                                    } while (__srcX >= __width);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11036
                                    __dstX -= FAST_ADVANCE; __dstPtr -= FAST_ADVANCE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11037
                                }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11038
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11039
                                __pix = __blackPixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11040
                            } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11041
                                double __nY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11042
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11043
                                /* rotate Y */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11044
                                __nY = (__sin * __pX) + __cosPY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11045
                                /* translate Y in source (origin to 0/0) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11046
                                __nY = __nY + __halfH + 0.5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11047
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11048
                                /* inside ? */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11049
                                if (__nY < 0) {
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 11050
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11051
                                    if (didFetchInRow) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11052
                                        break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11053
                                    }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11054
#endif
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11055
#ifdef FAST_ADVANCE2
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11056
                                    if (__blackPixel == 0) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11057
                                        do {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11058
                                            /* try advance by FAST_ADVANCE pixels ... */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11059
                                            __dstX += FAST_ADVANCE; __dstPtr += FAST_ADVANCE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11060
                                            if (__dstX >= __newWidth) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11061
                                                break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11062
                                            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11063
                                            __pX = (double)(__dstX + __minX);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11064
                                            __nY = (__sin * __pX) + __cosPY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11065
                                            __nY = __nY + __halfH + 0.5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11066
                                        } while (__nY < 0);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11067
                                        __dstX -= FAST_ADVANCE; __dstPtr -= FAST_ADVANCE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11068
                                    }
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 11069
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11070
                                    __pix = __blackPixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11071
                                } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11072
                                    int __srcY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11073
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11074
                                    __srcY = (int)__nY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11075
                                    /* inside ? */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11076
                                    if (__srcY >= __height) {
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 11077
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11078
                                        if (didFetchInRow) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11079
                                            break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11080
                                        }
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11081
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11082
#ifdef FAST_ADVANCE
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11083
                                        if (__blackPixel == 0) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11084
                                            do {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11085
                                                /* try advance by FAST_ADVANCE pixels ... */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11086
                                                __dstX += FAST_ADVANCE; __dstPtr += FAST_ADVANCE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11087
                                                if (__dstX >= __newWidth) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11088
                                                    break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11089
                                                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11090
                                                __pX = (double)(__dstX + __minX);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11091
                                                __nY = (__sin * __pX) + __cosPY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11092
                                                __nY = __nY + __halfH + 0.5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11093
                                                __srcY = (int)__nY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11094
                                            } while (__srcY >= __height);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11095
                                            __dstX -= FAST_ADVANCE; __dstPtr -= FAST_ADVANCE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11096
                                        }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11097
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11098
                                        __pix = __blackPixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11099
                                    } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11100
                                        /* fetch source pixel */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11101
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11102
                                        int idx;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11103
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11104
                                        didFetchInRow = 1;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11105
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11106
                                        idx = __srcY * __srcBytesPerRow + __srcX;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11107
                                        if ((unsigned)idx < __nSrcBytes) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11108
                                            __pix = __srcBytes[idx];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11109
                                        } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11110
                                            __pix = __blackPixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11111
                                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11112
                                    }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11113
                                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11114
                            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11115
                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11116
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11117
                        if (__pix != 0) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11118
                            *__dstPtr = __pix;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11119
                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11120
                        __dstPtr++;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11121
                    }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11122
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11123
                break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11124
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11125
            case 1:
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11126
                for (__dstY = 0; __dstY < __newHeight; __dstY++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11127
                    double __pY, __sinPY, __cosPY;
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 11128
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11129
                    int didFetchInRow = 0;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11130
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11131
                    __pY = (double)(__dstY + __minY);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11132
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11133
                    __sinPY = __sin * __pY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11134
                    __cosPY = __cos * __pY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11135
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11136
                    __dstPtr = __dstRowPtr;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11137
                    __dstMask = 0x80;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11138
                    __dstRowPtr += __dstBytesPerRow;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11139
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11140
                    for (__dstX = 0; __dstX < __newWidth; __dstX++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11141
                        double __pX, __nX;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11142
                        int __pix;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11143
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11144
                        /* translate X in destination (center to 0/0) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11145
                        __pX = (double)(__dstX + __minX);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11146
                        /* rotate X */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11147
                        __nX = (__cos * __pX) - __sinPY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11148
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11149
                        /* translate X in source (origin to 0/0) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11150
                        __nX = __nX + __halfW + 0.5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11151
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11152
                        /* inside ? */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11153
                        if (__nX < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11154
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11155
                            if (didFetchInRow) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11156
                                break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11157
                            }
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 11158
#endif
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 11159
#ifdef FAST_ADVANCE
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11160
                            if (__blackPixel == 0) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11161
                                do {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11162
                                    /* try advance by 8 pixels ... */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11163
                                    __dstX += 8; __dstPtr ++;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11164
                                    if (__dstX >= __newWidth) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11165
                                        break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11166
                                    }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11167
                                    __pX = (double)(__dstX + __minX);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11168
                                    __nX = (__cos * __pX) - __sinPY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11169
                                    __nX = __nX + __halfW + 0.5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11170
                                } while (__nX < 0);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11171
                                __dstX -= 8; __dstPtr--;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11172
                            }
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11173
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11174
                            __pix = __blackPixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11175
                        } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11176
                            int __srcX;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11177
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11178
                            __srcX = (int)__nX;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11179
                            /* inside ? */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11180
                            if (__srcX >= __width) {
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11181
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11182
                                if (didFetchInRow) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11183
                                    break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11184
                                }
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 11185
#endif
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 11186
#ifdef FAST_ADVANCE2
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11187
                                if (__blackPixel == 0) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11188
                                    do {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11189
                                        /* try advance by 8 pixels ... */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11190
                                        __dstX += 8; __dstPtr++;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11191
                                        if (__dstX >= __newWidth) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11192
                                            break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11193
                                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11194
                                        __pX = (double)(__dstX + __minX);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11195
                                        __nX = (__cos * __pX) - __sinPY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11196
                                        __nX = __nX + __halfW + 0.5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11197
                                        __srcX = (int)__nX;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11198
                                    } while (__srcX >= __width);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11199
                                    __dstX -= 8; __dstPtr--;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11200
                                }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11201
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11202
                                __pix = __blackPixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11203
                            } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11204
                                double __nY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11205
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11206
                                /* rotate Y */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11207
                                __nY = (__sin * __pX) + __cosPY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11208
                                /* translate Y in source (origin to 0/0) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11209
                                __nY = __nY + __halfH + 0.5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11210
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11211
                                /* inside ? */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11212
                                if (__nY < 0) {
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11213
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11214
                                    if (didFetchInRow) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11215
                                        break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11216
                                    }
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 11217
#endif
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 11218
#ifdef FAST_ADVANCE2
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11219
                                    if (__blackPixel == 0) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11220
                                        do {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11221
                                            /* try advance by 8 pixels ... */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11222
                                            __dstX += 8; __dstPtr++;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11223
                                            if (__dstX >= __newWidth) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11224
                                                break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11225
                                            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11226
                                            __pX = (double)(__dstX + __minX);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11227
                                            __nY = (__sin * __pX) + __cosPY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11228
                                            __nY = __nY + __halfH + 0.5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11229
                                        } while (__nY < 0);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11230
                                        __dstX -= 8; __dstPtr--;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11231
                                    }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11232
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11233
                                    __pix = __blackPixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11234
                                } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11235
                                    int __srcY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11236
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11237
                                    __srcY = (int)__nY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11238
                                    /* inside ? */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11239
                                    if (__srcY >= __height) {
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 11240
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11241
                                        if (didFetchInRow) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11242
                                            break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11243
                                        }
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 11244
#endif
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 11245
#ifdef FAST_ADVANCE
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11246
                                        if (__blackPixel == 0) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11247
                                            do {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11248
                                                /* try advance by 8 pixels ... */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11249
                                                __dstX += 8; __dstPtr++;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11250
                                                if (__dstX >= __newWidth) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11251
                                                    break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11252
                                                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11253
                                                __pX = (double)(__dstX + __minX);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11254
                                                __nY = (__sin * __pX) + __cosPY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11255
                                                __nY = __nY + __halfH + 0.5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11256
                                                __srcY = (int)__nY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11257
                                            } while (__srcY >= __height);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11258
                                            __dstX -= 8; __dstPtr--;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11259
                                        }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11260
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11261
                                        __pix = __blackPixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11262
                                    } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11263
                                        /* fetch source pixel */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11264
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11265
                                        int idx, pV;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11266
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11267
                                        didFetchInRow = 1;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11268
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11269
                                        idx = __srcY * __srcBytesPerRow + (__srcX >> 3);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11270
                                        if ((unsigned)idx < __nSrcBytes) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11271
                                            pV = __srcBytes[idx];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11272
                                            __pix = (pV & (0x80 >> (__srcX & 7))) ? 1 : 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11273
                                        } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11274
                                            __pix = __blackPixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11275
                                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11276
                                    }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11277
                                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11278
                            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11279
                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11280
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11281
                        /* store pixel */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11282
                        if (__pix != 0) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11283
                            *__dstPtr |= __dstMask;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11284
                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11285
                        __dstMask >>= 1;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11286
                        if (__dstMask == 0) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11287
                            __dstMask = 0x80;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11288
                            __dstPtr++;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11289
                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11290
                    }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11291
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11292
                break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11293
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11294
            case 24:
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11295
                for (__dstY = 0; __dstY < __newHeight; __dstY++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11296
                    double __pY, __sinPY, __cosPY;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11297
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11298
                    int didFetchInRow = 0;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11299
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11300
                    __pY = (double)(__dstY + __minY);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11301
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11302
                    __sinPY = __sin * __pY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11303
                    __cosPY = __cos * __pY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11304
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11305
                    __dstPtr = __dstRowPtr;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11306
                    __dstRowPtr += __dstBytesPerRow;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11307
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11308
                    for (__dstX = 0; __dstX < __newWidth; __dstX++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11309
                        double __pX, __nX;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11310
                        unsigned __pix;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11311
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11312
                        /* translate X in destination (center to 0/0) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11313
                        __pX = (double)(__dstX + __minX);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11314
                        /* rotate X */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11315
                        __nX = (__cos * __pX) - __sinPY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11316
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11317
                        /* translate X in source (origin to 0/0) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11318
                        __nX = __nX + __halfW + 0.5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11319
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11320
                        /* inside ? */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11321
                        if (__nX < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11322
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11323
                            if (didFetchInRow) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11324
                                break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11325
                            }
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 11326
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11327
                            __pix = __blackPixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11328
                        } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11329
                            int __srcX;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11330
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11331
                            __srcX = (int)__nX;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11332
                            /* inside ? */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11333
                            if (__srcX >= __width) {
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11334
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11335
                                if (didFetchInRow) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11336
                                    break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11337
                                }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11338
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11339
                                __pix = __blackPixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11340
                            } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11341
                                double __nY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11342
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11343
                                /* rotate Y */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11344
                                __nY = (__sin * __pX) + __cosPY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11345
                                /* translate Y in source (origin to 0/0) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11346
                                __nY = __nY + __halfH + 0.5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11347
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11348
                                /* inside ? */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11349
                                if (__nY < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11350
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11351
                                    if (didFetchInRow) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11352
                                        break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11353
                                    }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11354
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11355
                                    __pix = __blackPixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11356
                                } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11357
                                    int __srcY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11358
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11359
                                    __srcY = (int)__nY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11360
                                    /* inside ? */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11361
                                    if (__srcY >= __height) {
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11362
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11363
                                        if (didFetchInRow) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11364
                                            break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11365
                                        }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11366
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11367
                                        __pix = __blackPixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11368
                                    } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11369
                                        /* fetch source pixel */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11370
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11371
                                        int idx;
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11372
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11373
                                        didFetchInRow = 1;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11374
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11375
                                        idx = __srcY * __srcBytesPerRow + __srcX + __srcX + __srcX;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11376
                                        if ((unsigned)idx < __nSrcBytes) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11377
                                            __pix = __srcBytes[idx];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11378
                                            __pix = (__pix<<8) | __srcBytes[idx+1];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11379
                                            __pix = (__pix<<8) | __srcBytes[idx+2];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11380
                                        } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11381
                                            __pix = __blackPixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11382
                                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11383
                                    }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11384
                                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11385
                            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11386
                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11387
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11388
                        /* store pixel */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11389
                        if (__pix != 0) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11390
                            __dstPtr[0] = (__pix >> 16 & 0xFF);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11391
                            __dstPtr[1] = (__pix >> 8) & 0xFF;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11392
                            __dstPtr[2] = __pix & 0xFF;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11393
                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11394
                        __dstPtr += 3;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11395
                    }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11396
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11397
                break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11398
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11399
            default:
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11400
                for (__dstY = 0; __dstY < __newHeight; __dstY++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11401
                    double __pY, __sinPY, __cosPY;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11402
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11403
                    int didFetchInRow = 0;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11404
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11405
                    __pY = (double)(__dstY + __minY);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11406
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11407
                    __sinPY = __sin * __pY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11408
                    __cosPY = __cos * __pY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11409
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11410
                    __dstPtr = __dstRowPtr;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11411
                    __dstMask = 0x80;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11412
                    __dstRowPtr += __dstBytesPerRow;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11413
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11414
                    for (__dstX = 0; __dstX < __newWidth; __dstX++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11415
                        double __pX, __nX;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11416
                        OBJ __pix;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11417
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11418
                        /* translate X in destination (center to 0/0) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11419
                        __pX = (double)(__dstX + __minX);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11420
                        /* rotate X */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11421
                        __nX = (__cos * __pX) - __sinPY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11422
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11423
                        /* translate X in source (origin to 0/0) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11424
                        __nX = __nX + __halfW + 0.5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11425
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11426
                        /* inside ? */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11427
                        if (__nX < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11428
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11429
                            if (didFetchInRow) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11430
                                break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11431
                            }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11432
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11433
                            __pix = blackPixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11434
                        } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11435
                            int __srcX;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11436
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11437
                            __srcX = (int)__nX;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11438
                            /* inside ? */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11439
                            if (__srcX >= __width) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11440
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11441
                                if (didFetchInRow) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11442
                                    break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11443
                                }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11444
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11445
                                __pix = blackPixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11446
                            } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11447
                                double __nY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11448
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11449
                                /* rotate Y */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11450
                                __nY = (__sin * __pX) + __cosPY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11451
                                /* translate Y in source (origin to 0/0) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11452
                                __nY = __nY + __halfH + 0.5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11453
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11454
                                /* inside ? */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11455
                                if (__nY < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11456
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11457
                                    if (didFetchInRow) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11458
                                        break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11459
                                    }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11460
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11461
                                    __pix = blackPixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11462
                                } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11463
                                    int __srcY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11464
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11465
                                    __srcY = (int)__nY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11466
                                    /* inside ? */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11467
                                    if (__srcY >= __height) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11468
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11469
                                        if (didFetchInRow) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11470
                                            break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11471
                                        }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11472
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11473
                                        __pix = blackPixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11474
                                    } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11475
                                        /* fetch source pixel */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11476
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11477
                                        static struct inlineCache valAt = _ILC2;
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11478
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11479
                                        didFetchInRow = 1;
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11480
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11481
                                        __pix = (*valAt.ilc_func)(self,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11482
                                                              @symbol(pixelAtX:y:),
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11483
                                                              nil, &valAt,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11484
                                                              __MKSMALLINT(__srcX),
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11485
                                                              __MKSMALLINT(__srcY));
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11486
                                    }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11487
                                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11488
                            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11489
                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11490
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11491
                        /* store pixel */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11492
                        {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11493
                            static struct inlineCache atPutVal = _ILC3;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11494
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11495
                            if (__pix != __MKSMALLINT(0)) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11496
                                (*atPutVal.ilc_func)(newImage,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11497
                                                      @symbol(pixelAtX:y:put:),
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11498
                                                      nil, &atPutVal,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11499
                                                      __MKSMALLINT(__dstX),
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11500
                                                      __MKSMALLINT(__dstY),
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11501
                                                      __pix
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11502
                                                     );
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11503
                            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11504
                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11505
                    }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11506
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11507
                break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11508
        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11509
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11510
        bad = false;
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11511
    }
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11512
%}.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11513
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11514
    bad ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11515
        "/ should not happen
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11516
        self primitiveFailed
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11517
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11518
"/        sinRot := radians negated sin.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11519
"/        cosRot := radians negated cos.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11520
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11521
"/        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
 11522
"/            pY := (dstY + minY).
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11523
"/            sinPY := (sinRot * pY).
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11524
"/            cosPY := (cosRot * pY).
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11525
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11526
"/            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
 11527
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11528
"/                "/ translate center to origin
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11529
"/                pX := (dstX + minX).
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11530
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11531
"/                nX := (cosRot * pX) - sinPY.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11532
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11533
"/                "/ translate in source
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11534
"/                srcX := nX + halfW.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11535
"/                srcX := srcX rounded.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11536
"/                "/ inside ?
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11537
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11538
"/                (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
 11539
"/                    nY := (sinRot * pX) + cosPY.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11540
"/                    srcY := nY + halfH.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11541
"/                    srcY := srcY rounded.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11542
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11543
"/                    "/ inside ?
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11544
"/                    (srcY >= 0 and:[srcY < height]) ifTrue:[
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 11545
"/                        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
 11546
"/                    ] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11547
"/                        pix := blackPixel.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11548
"/                    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11549
"/                ] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11550
"/                    pix := blackPixel.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11551
"/                ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11552
"/                pix ~~ blackPixel ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11553
"/                    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
 11554
"/                ]
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11555
"/            ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11556
"/        ].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11557
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11558
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11559
    ^ newImage
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11560
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11561
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11562
     |i|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11563
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 11564
     i := Smalltalk imageFromFileNamed:'bitmaps/xpmBitmaps/misc_icons/BOOK.xpm' inPackage:'stx:goodies'.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11565
     i inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11566
     (i rotated:45) inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11567
     (i rotated:90) inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11568
     (i rotated:91) inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11569
     (i rotated:95) inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11570
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11571
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11572
     |i|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11573
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 11574
     i := Smalltalk imageFromFileNamed:'bitmaps/gifImages/garfield.gif' inPackage:'stx:goodies'.
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 11575
     i := Depth24Image fromImage:i.
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 11576
     (i rotated:200) inspect
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11577
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11578
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11579
     |i|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11580
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 11581
     i := Smalltalk imageFromFileNamed:'bitmaps/gifImages/garfield.gif' inPackage:'stx:goodies'.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11582
     Transcript showCR:(
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11583
        Time millisecondsToRun:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11584
           i rotated:45.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11585
        ]
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11586
     ).
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11587
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11588
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11589
     |v i rI rot|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11590
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 11591
     i := Smalltalk imageFromFileNamed:'bitmaps/xpmBitmaps/misc_icons/BOOK.xpm' inPackage:'stx:goodies'.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11592
     v := View new extent:(i width max:100)@(i height max:100).
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11593
     v openAndWait.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11594
     rot := 0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11595
     [true] whileTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11596
        rI := i rotated:rot.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11597
        rI := rI onDevice:v device.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11598
        v clear.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11599
        v displayForm:rI x:(v width-rI width)//2 y:(v height-rI height)//2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11600
        rot := rot + 5.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11601
        rI close.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11602
     ]
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11603
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11604
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11605
     |v i rI rot|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11606
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 11607
     i := Smalltalk imageFromFileNamed:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies'.
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 11608
     v := View new extent:400@400.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11609
     v openAndWait.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11610
     rot := 0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11611
     [true] whileTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11612
        rI := i rotated:rot.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11613
        rI := rI onDevice:v device.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11614
        v clear.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11615
        v displayForm:rI x:(v width-rI width)//2 y:(v height-rI height)//2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11616
        rot := rot + 5.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11617
        rI close.
4952
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11618
     ]
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11619
    "
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11620
    "
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11621
     |v i rI rot|
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11622
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11623
     i := Form width:200 height:100 onDevice:Screen current.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11624
     i clear.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11625
     i displayLineFrom:(0@0) to:(199@0).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11626
     i displayLineFrom:(199@0) to:(199@99).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11627
     i displayLineFrom:(199@99) to:(0@99).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11628
     i displayLineFrom:(0@99) to:(0@0).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11629
     i displayLineFrom:(0@0) to:(199@100).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11630
     i displayLineFrom:(199@0) to:(0@100).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11631
     i := Image fromForm:i.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11632
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11633
     v := View new extent:400@400.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11634
     v openAndWait.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11635
     rot := 0.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11636
     [true] whileTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11637
        rI := i rotated:rot.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11638
        rI := rI onDevice:v device.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11639
        v clear.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11640
        v displayForm:rI x:(v width-rI width)//2 y:(v height-rI height)//2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11641
        rot := rot + 5.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11642
        rI close.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11643
        Delay waitForSeconds:0.1.
4952
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11644
     ]
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11645
    "
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11646
    "
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11647
     |v i rI rot|
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11648
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11649
     i := Form width:200 height:100 onDevice:Screen current.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11650
     i clear.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11651
     i displayLineFrom:(0@0) to:(199@0).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11652
     i displayLineFrom:(199@0) to:(199@99).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11653
     i displayLineFrom:(199@99) to:(0@99).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11654
     i displayLineFrom:(0@99) to:(0@0).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11655
     i displayLineFrom:(0@0) to:(199@100).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11656
     i displayLineFrom:(199@0) to:(0@100).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11657
     i := Image fromForm:i.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11658
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11659
     v := View new extent:400@400.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11660
     v openAndWait.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11661
     rot := 0.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11662
     [true] whileTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11663
        rI := i rotated:rot.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11664
        rI := rI onDevice:v device.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11665
        v clear.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11666
        v displayForm:rI x:(v width-rI width)//2 y:(v height-rI height)//2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11667
        rot := rot + 30.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11668
        rI close.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11669
        Delay waitForSeconds:0.3.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11670
     ]
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11671
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11672
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11673
    "Modified: 22.4.1997 / 17:36:37 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 11674
!
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 11675
54
29a6b2f8e042 *** empty log message ***
claus
parents: 46
diff changeset
 11676
lightened
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 11677
    "return a new image which is slightly brighter than the receiver.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 11678
     The receiver must be a palette image (currently).
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11679
     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
 11680
     CAVEAT: Need an argument, which specifies by how much it should be lighter."
54
29a6b2f8e042 *** empty log message ***
claus
parents: 46
diff changeset
 11681
5655
37bd5c7eb765 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 5643
diff changeset
 11682
    ^ self copyWithColorMapProcessing:[:clr | clr lightened]
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11683
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11684
    "
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11685
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11686
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') lightened inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11687
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') darkened inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11688
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') darkened darkened inspect
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11689
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11690
5655
37bd5c7eb765 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 5643
diff changeset
 11691
    "Modified: / 24-11-2010 / 11:17:55 / cg"
54
29a6b2f8e042 *** empty log message ***
claus
parents: 46
diff changeset
 11692
!
29a6b2f8e042 *** empty log message ***
claus
parents: 46
diff changeset
 11693
134
claus
parents: 132
diff changeset
 11694
magnifiedBy:scale
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 11695
    "return a new image magnified by scalePoint, aPoint.
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
 11696
     If non-integral magnify is asked for, pass the work on to 'hardMagnifyBy:'
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
 11697
     while simple (integral) magnifications are handled here."
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11698
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 11699
    |scalePoint mX mY
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11700
     magX      "{ Class: SmallInteger }"   "new version of stc can find this out itself..."
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11701
     magY      "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11702
     srcOffset "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11703
     dstOffset "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11704
     w         "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11705
     h         "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11706
     first
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 11707
     newWidth newHeight newImage newBits newMask
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 11708
     bitsPerPixel newBytesPerRow oldBytesPerRow
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 11709
     bytes|
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11710
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 11711
    scalePoint := scale asPoint.
2772
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
 11712
    mX := scalePoint x.
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
 11713
    mY := scalePoint y.
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11714
    ((mX <= 0) or:[mY <= 0]) ifTrue:[^ nil].
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11715
    ((mX = 1) and:[mY = 1]) ifTrue:[^ self].
48194c26a46c Initial revision
claus
parents:
diff changeset
 11716
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11717
    ((mX isMemberOf:SmallInteger) and:[mY isMemberOf:SmallInteger]) ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11718
        ^ self hardMagnifiedBy:scalePoint
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 11719
    ].
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 11720
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 11721
    bytes := self bits.
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
 11722
    bitsPerPixel := self depth.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11723
    oldBytesPerRow := ((width * bitsPerPixel) + 7) // 8.
48194c26a46c Initial revision
claus
parents:
diff changeset
 11724
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11725
    w := width.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11726
    h := height.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11727
    magX := mX.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11728
    magY := mY.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11729
2772
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
 11730
    newWidth := w * magX.
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
 11731
    newHeight := h * magY.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11732
    newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8.
48194c26a46c Initial revision
claus
parents:
diff changeset
 11733
    newBits := ByteArray uninitializedNew:(newBytesPerRow * newHeight).
48194c26a46c Initial revision
claus
parents:
diff changeset
 11734
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 11735
    mask notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11736
        newMask := (mask magnifiedBy:scalePoint)
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 11737
    ].
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 11738
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11739
    newImage := self species new.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11740
    newImage
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11741
        width:newWidth
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11742
        height:newHeight
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11743
        photometric:photometric
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11744
        samplesPerPixel:samplesPerPixel
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11745
        bitsPerSample:bitsPerSample
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11746
        colorMap:colorMap copy
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11747
        bits:newBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11748
        mask:newMask.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11749
48194c26a46c Initial revision
claus
parents:
diff changeset
 11750
    mX = 1 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11751
        "expand rows only"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11752
        srcOffset := 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11753
        dstOffset := 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11754
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11755
        1 to:h do:[:row |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11756
            1 to:magY do:[:i |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11757
                newBits replaceFrom:dstOffset
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11758
                        to:(dstOffset + oldBytesPerRow - 1)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11759
                        with:bytes
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11760
                        startingAt:srcOffset.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11761
                dstOffset := dstOffset + newBytesPerRow
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11762
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11763
            srcOffset := srcOffset + oldBytesPerRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11764
        ].
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11765
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11766
        "expand cols"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11767
        (mX > 1) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11768
            dstOffset := 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11769
            srcOffset := 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11770
            1 to:h do:[:row |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11771
                self magnifyRowFrom:bytes
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11772
                     offset:srcOffset
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11773
                     into:newBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11774
                     offset:dstOffset
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11775
                     factor:mX.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11776
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11777
                first := dstOffset.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11778
                dstOffset := dstOffset + newBytesPerRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11779
                " and copy for row expansion "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11780
                2 to:magY do:[:i |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11781
                    newBits replaceFrom:dstOffset
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11782
                            to:(dstOffset + newBytesPerRow - 1)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11783
                            with:newBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11784
                            startingAt:first.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11785
                    dstOffset := dstOffset + newBytesPerRow
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11786
                ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11787
                srcOffset := srcOffset + oldBytesPerRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11788
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11789
        ]
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11790
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
 11791
    ^ newImage
48194c26a46c Initial revision
claus
parents:
diff changeset
 11792
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11793
    "
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11794
     ((Image fromFile:'goodies/bitmaps/gifImages/claus.gif') magnifiedBy:1@2)
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11795
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11796
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11797
    "Modified: 24.4.1997 / 18:32:04 / cg"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
 11798
!
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
 11799
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11800
magnifiedPreservingRatioTo:anExtent
154
claus
parents: 153
diff changeset
 11801
    "return a new image magnified to fit into anExtent,
7242
bf3a75233d55 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7230
diff changeset
 11802
     preserving the receiver's width/height ratio.
154
claus
parents: 153
diff changeset
 11803
     (i.e. not distorting the image).
claus
parents: 153
diff changeset
 11804
     See also #magnifiedTo: and #magnifiedBy:"
claus
parents: 153
diff changeset
 11805
claus
parents: 153
diff changeset
 11806
    |rX rY|
claus
parents: 153
diff changeset
 11807
claus
parents: 153
diff changeset
 11808
    rX := anExtent x / self width.
claus
parents: 153
diff changeset
 11809
    rY := anExtent y / self height.
claus
parents: 153
diff changeset
 11810
    ^ self magnifiedBy:(rX min:rY)
claus
parents: 153
diff changeset
 11811
claus
parents: 153
diff changeset
 11812
    "
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11813
     ((Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') magnifiedPreservingRatioTo:100@100)
154
claus
parents: 153
diff changeset
 11814
claus
parents: 153
diff changeset
 11815
    in contrast to:
claus
parents: 153
diff changeset
 11816
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11817
     ((Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') magnifiedTo:100@100)
1630
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 11818
    "
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 11819
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 11820
    "Modified: 22.4.1997 / 12:33:46 / cg"
154
claus
parents: 153
diff changeset
 11821
!
claus
parents: 153
diff changeset
 11822
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11823
magnifiedTo:anExtent
154
claus
parents: 153
diff changeset
 11824
    "return a new image magnified to have the size specified by extent.
claus
parents: 153
diff changeset
 11825
     This may distort the image if the arguments ratio is not the images ratio.
claus
parents: 153
diff changeset
 11826
     See also #magnifiedPreservingRatioTo: and #magnifiedBy:"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 11827
134
claus
parents: 132
diff changeset
 11828
    ^ self magnifiedBy:(anExtent / self extent)
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 11829
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 11830
    "
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 11831
     ((Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') magnifiedTo:100@100)
154
claus
parents: 153
diff changeset
 11832
claus
parents: 153
diff changeset
 11833
    in contrast to:
claus
parents: 153
diff changeset
 11834
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 11835
     ((Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') magnifiedPreservingRatioTo:100@100)
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 11836
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 11837
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 11838
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11839
mixed:amount with:aColor
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11840
    "return a new image which is blended with some color;
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11841
     amount determines how much of the blending color is applied (0..)
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11842
     where 0 means: blending color pure.
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11843
     The receiver must be a palette image (currently).
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11844
     CAVEAT: this only works with palette images (i.e. not for rgb or greyScale).
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11845
     CAVEAT: Need an argument, which specifies by how much it should be lighter."
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11846
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11847
     ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11848
        copyWithColorMapProcessing:[:clr | clr mixed:amount with:aColor]
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11849
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11850
    "
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11851
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11852
     ((Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') mixed:0.0 with:Color red) inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11853
     ((Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') mixed:0.1 with:Color red) inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11854
     ((Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') mixed:0.25 with:Color red) inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11855
     ((Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') mixed:0.5 with:Color red) inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11856
     ((Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') mixed:1 with:Color red) inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11857
     ((Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') mixed:2 with:Color red) inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11858
     ((Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') mixed:10 with:Color red) inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11859
    "
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11860
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11861
    "Modified: 24.4.1997 / 18:31:23 / cg"
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11862
!
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11863
1762
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11864
negative
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11865
    "return a new image which is a negative of the receiver.
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11866
     The receiver must be a palette image (currently)."
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11867
1763
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 11868
    |newImage|
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 11869
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 11870
    colorMap isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11871
        photometric == #blackIs0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11872
            newImage := self copy.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11873
            newImage photometric:#whiteIs0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11874
            ^ newImage
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11875
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11876
        photometric == #whiteIs0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11877
            newImage := self copy.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11878
            newImage photometric:#blackIs0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11879
            ^ newImage
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11880
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11881
        ^ nil
1763
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 11882
    ].
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 11883
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11884
     ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11885
        copyWithColorMapProcessing:[:clr |
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 11886
                Color
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 11887
                    redByte:(255 - clr redByte)
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 11888
                    greenByte:(255 - clr greenByte)
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 11889
                    blueByte:(255 - clr blueByte)
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 11890
            ]
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11891
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11892
    "
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11893
     (Image fromFile:'goodies/bitmaps/gifImages/claus.gif') inspect
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11894
     (Image fromFile:'goodies/bitmaps/gifImages/claus.gif') negative inspect
1762
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11895
    "
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11896
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 11897
    "Created: / 20-06-1997 / 13:13:41 / cg"
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 11898
    "Modified: / 31-01-2017 / 14:43:19 / stefan"
1762
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11899
!
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11900
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11901
rotated:degrees
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11902
    "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
 11903
     degrees clockwise.
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 11904
     Notice that the resulting image has a different extent.
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11905
     If rotation is heavily used, the workHorse methods
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11906
     (#easyRotateBitsInto:angle: and #hardRotateBitsInto:angle) may
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11907
     be redefined in concrete image subclasses."
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11908
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 11909
    |nW nH newImage d|
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11910
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11911
    d := degrees.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11912
    [d < 0] whileTrue:[d := d + 360].
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11913
    d >= 360 ifTrue:[d := d \\ 360].
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11914
    d := d truncated.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11915
    d = 0 ifTrue:[^ self].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11916
    ((d ~= 90) and:[(d ~= 270) and:[d ~= 180]]) ifTrue:[
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 11917
        ^ self hardRotated:d
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11918
    ].
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11919
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11920
    d = 180 ifTrue:[
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 11921
        nW := width.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 11922
        nH := height.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11923
    ] ifFalse:[
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 11924
        nW := height.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 11925
        nH := width.
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11926
    ].
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11927
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11928
    newImage := self species new.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11929
    newImage width:nW.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11930
    newImage height:nH.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 11931
    newImage createPixelStore.
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11932
    newImage photometric:photometric.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11933
    newImage samplesPerPixel:samplesPerPixel.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11934
    newImage bitsPerSample:bitsPerSample.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11935
    newImage colorMap:colorMap copy.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11936
    mask notNil ifTrue:[
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 11937
        newImage mask:(mask rotated:degrees)
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11938
    ].
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11939
7534
0b7e23635791 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7529
diff changeset
 11940
    self easyRotateBitsInto:newImage angle:d.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11941
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11942
    ^ newImage
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 11943
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11944
    "
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11945
     |i|
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11946
7529
5f77a718b7bd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7523
diff changeset
 11947
     i := Image fromFile:'../../goodies/bitmaps/gifImages/claus.gif'.
7534
0b7e23635791 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7529
diff changeset
 11948
     i inspect.
0b7e23635791 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7529
diff changeset
 11949
     (i rotated:45) inspect.
0b7e23635791 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7529
diff changeset
 11950
     (i rotated:90) inspect.
0b7e23635791 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7529
diff changeset
 11951
     (i rotated:180) inspect.
0b7e23635791 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7529
diff changeset
 11952
     (i rotated:270) inspect.
0b7e23635791 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7529
diff changeset
 11953
    "
0b7e23635791 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7529
diff changeset
 11954
    "
0b7e23635791 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7529
diff changeset
 11955
     |i|
0b7e23635791 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7529
diff changeset
 11956
0b7e23635791 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7529
diff changeset
 11957
     i := Image fromFile:'../../goodies/bitmaps/gifImages/claus.gif'.
7529
5f77a718b7bd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7523
diff changeset
 11958
     i := Depth24Image fromImage:i.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11959
     i inspect.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11960
     (i rotated:45) inspect.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11961
     (i rotated:90) inspect.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11962
     (i rotated:180) inspect.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11963
     (i rotated:270) inspect.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11964
    "
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11965
    "
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11966
     |i|
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11967
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11968
     i := Image fromFile:'goodies/bitmaps/xpmBitmaps/misc_icons/BOOK.xpm'.
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11969
     i inspect.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11970
     (i rotated:90) inspect.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11971
     (i rotated:180) inspect.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11972
     (i rotated:270) inspect.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11973
    "
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11974
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11975
    "Modified: 24.4.1997 / 18:33:42 / cg"
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11976
!
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11977
6624
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11978
slightlyDarkened
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11979
    "return a new image which is slightly darker than the receiver.
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11980
     The receiver must be a palette image (currently).
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11981
     CAVEAT: this only works with palette images (i.e. not for rgb or greyScale).
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11982
     CAVEAT: Need an argument, which specifies by how much it should be lighter."
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11983
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11984
    ^ self copyWithColorMapProcessing:[:clr | clr slightlyDarkened]
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11985
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11986
    "
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11987
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') inspect
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11988
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') lightened inspect
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11989
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') darkened inspect
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11990
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') darkened darkened inspect
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11991
    "
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11992
!
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11993
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11994
slightlyLightened
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11995
    "return a new image which is slightly brighter than the receiver.
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11996
     The receiver must be a palette image (currently).
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11997
     CAVEAT: this only works with palette images (i.e. not for rgb or greyScale).
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11998
     CAVEAT: Need an argument, which specifies by how much it should be lighter."
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11999
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 12000
    ^ self copyWithColorMapProcessing:[:clr | clr slightlyLightened]
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 12001
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 12002
    "
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 12003
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') inspect
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 12004
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') lightened inspect
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 12005
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') darkened inspect
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 12006
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') darkened darkened inspect
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 12007
    "
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 12008
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 12009
    "Modified: / 24-11-2010 / 11:17:55 / cg"
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 12010
!
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 12011
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12012
threeDProjected:fraction1 and:fraction2
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12013
    "return a 3D-projected version"
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12014
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 12015
    |dx1 dx2 newImage newBits
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 12016
     blackPixel halfH m myDepth maskBits pix fr fl ml mr dm fractX my fy dstY o1 df|
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12017
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12018
    newImage := self species new.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12019
    newImage width:width.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12020
    newImage height:height.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12021
    newImage createPixelStore.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12022
    newBits := newImage bits.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12023
    newImage photometric:photometric.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12024
    newImage samplesPerPixel:samplesPerPixel.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12025
    newImage bitsPerSample:bitsPerSample.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12026
    newImage colorMap:colorMap copy.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12027
    newImage maskedPixelsAre0:maskedPixelsAre0.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12028
    mask notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12029
        newImage mask:(mask threeDProjected:fraction1 and:fraction2)
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12030
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12031
        self isMask ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12032
            self depth ~~ 1 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12033
                m := ImageMask width:width height:height.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12034
                m bits:(maskBits := ByteArray new:(m bytesPerRow * height)).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12035
                maskBits atAllPut:16rFF.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12036
                newImage mask:(m threeDProjected:fraction1 and:fraction2)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12037
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12038
        ]
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12039
    ].
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12040
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12041
    myDepth := self depth.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12042
    myDepth == 1 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12043
        blackPixel := 0.
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12044
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12045
        maskedPixelsAre0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12046
            blackPixel := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12047
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12048
            blackPixel := self valueFromColor:Color black.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12049
            blackPixel isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12050
                blackPixel := self valueFromColor:Color white.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12051
                blackPixel isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12052
                    blackPixel := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12053
                ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12054
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12055
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12056
        self isMask ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12057
            blackPixel := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12058
        ].
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12059
    ].
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12060
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12061
    newBits atAllPut:0.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12062
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12063
    "/ now, walk over destination pixels,
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12064
    "/ fetching from source.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12065
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12066
    halfH := (height - 1) / 2.0.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12067
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12068
    "/  --------------------------------------------------------------
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12069
    "/  |**************                                              |
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12070
    "/  |              ************                                  | dx1
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12071
    "/  |                          *************                     |
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12072
    "/  |                                       **********           |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12073
    "/  |fl                          fy                   ***********|
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12074
    "/  |                                                            | fr
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12075
    "/  |                                                            | Mr  (!!= Ml)      |
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12076
    "/  |Ml                          my                              | fr               | dm (=Mr-Ml)
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12077
    "/  |                                                     *******|                  |
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12078
    "/  |                            fy              *********       |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12079
    "/  |fl                                 *********                |
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12080
    "/  |                          *********                         | dx2
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12081
    "/  |                 *********                                  |
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12082
    "/  |        *********                                           |
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12083
    "/  |********                                                    |
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12084
    "/  --------------------------------------------------------------
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12085
    dx1 := height * fraction1.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12086
    dx2 := height * fraction2.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12087
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12088
    fr := (height - dx1 - dx2) / 2.0.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12089
    fl := (height) / 2.0.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12090
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12091
    ml := height / 2.0.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12092
    mr := dx1+fr.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12093
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12094
    dm := mr-ml.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12095
    df := fr-fl.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12096
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12097
    0 to:width-1 do:[:srcX |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12098
        fractX := srcX / width.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12099
        my := ml + (dm * fractX).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12100
        fy := fl + (df * fractX).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12101
        o1 := dx1 * fractX.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12102
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12103
        0 to:height-1 do:[:srcY |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12104
            srcY < halfH ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12105
                dstY := o1 + (fy * (srcY / halfH)).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12106
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12107
                dstY := my + (fy * ((srcY-halfH) / halfH)).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12108
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12109
            pix := self pixelAtX:srcX y:srcY.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12110
            dstY < 0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12111
                ifTrue:[dstY := 0]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12112
                ifFalse:[ dstY >= height ifTrue:[dstY := height-1]].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12113
            newImage pixelAtX:srcX y:dstY truncated put:pix.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12114
        ].
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12115
    ].
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12116
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12117
    ^ newImage
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12118
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12119
    "
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12120
     |i|
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12121
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12122
     i := Smalltalk imageFromFileNamed:'bitmaps/gifImages/garfield.gif' inPackage:'stx:goodies'.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12123
     i := Depth24Image fromImage:i.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12124
     (i threeDProjected:0.1 and:0.3) inspect
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12125
     (i threeDProjected:0.1 and:0.1) inspect
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12126
    "
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 12127
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 12128
    "Modified: / 31-01-2017 / 15:04:22 / stefan"
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12129
!
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12130
3905
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12131
withColorResolutionReducedBy:numBits
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12132
    "return a new image with the same picture as the receiver, but reduced colorResolution;
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12133
     that is, the lower numBits are cleared in the r/g/b color components.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12134
     If anything fails, return nil."
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12135
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12136
    |xMax yMax r g b nR nG nB clr pix map revMap n_clr n_pix mask anyChange
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12137
     newColors newColorArray newImage extMask extBits newPixelValue|
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12138
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12139
    numBits > 7 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12140
        ^ nil
3905
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12141
    ].
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12142
    mask := (16rFF bitShift:numBits) bitAnd:16rFF.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12143
    extMask := (1 bitShift:numBits).
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12144
    extBits := extMask - 1.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12145
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12146
    anyChange := false.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12147
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12148
    newColors := Set new.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12149
    newColorArray := OrderedCollection new.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12150
    map := Array new:256.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12151
    revMap := OrderedCollection new.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12152
4317
a24172a52a76 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4296
diff changeset
 12153
    newImage := self class width:width height:height depth:self depth.
3905
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12154
    newImage photometric:photometric.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12155
    newImage colorMap:(self colorMap copy).
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12156
    newImage bits:(self bits copy).
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12157
    newImage mask:(self mask copy).
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12158
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12159
    xMax := width - 1.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12160
    yMax := height - 1.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12161
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12162
    newPixelValue :=
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12163
        [:image :pixelValue |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12164
            |r g b nR nG nB|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12165
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12166
            r := image redBitsOf:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12167
            g := image greenBitsOf:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12168
            b := image blueBitsOf:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12169
            nR := r bitAnd:mask. (nR bitAnd:extMask)~~0 ifTrue:[nR := nR bitOr:extBits].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12170
            nG := g bitAnd:mask. (nG bitAnd:extMask)~~0 ifTrue:[nG := nG bitOr:extBits].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12171
            nB := b bitAnd:mask. (nB bitAnd:extMask)~~0 ifTrue:[nB := nB bitOr:extBits].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12172
            image valueFromRedBits:nR greenBits:nG blueBits:nB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12173
        ].
3905
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12174
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12175
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 12176
    photometric ~~ #palette ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12177
        "/ direct manipulation of the pixels
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12178
        0 to:yMax do:[:y |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12179
            0 to:xMax do:[:x |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12180
                pix := self pixelAtX:x y:y.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12181
                n_pix := newPixelValue value:self value:pix.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12182
                n_pix ~= pix ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12183
                    newImage pixelAtX:x y:y put:n_pix.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12184
                    anyChange := true.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12185
                ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12186
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12187
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12188
        anyChange ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12189
            ^ nil
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12190
        ].
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 12191
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12192
        "/ manipulate the colormap
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12193
        0 to:yMax do:[:y |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12194
            0 to:xMax do:[:x |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12195
                pix := self pixelAtX:x y:y.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12196
                (n_pix := map at:pix+1) isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12197
                    clr := self colorAtX:x y:y.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12198
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12199
                    r := clr redByte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12200
                    g := clr greenByte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12201
                    b := clr blueByte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12202
                    nR := r bitAnd:mask. (nR bitAnd:extMask)~~0 ifTrue:[nR := nR bitOr:extBits].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12203
                    nG := g bitAnd:mask. (nR bitAnd:extMask)~~0 ifTrue:[nR := nR bitOr:extBits].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12204
                    nB := b bitAnd:mask. (nR bitAnd:extMask)~~0 ifTrue:[nR := nR bitOr:extBits].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12205
                    n_clr := Color redByte:nR greenByte:nG blueByte:nB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12206
                    (newColors includes:n_clr) ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12207
                        newColors add:n_clr.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12208
                        newColorArray add:n_clr.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12209
                        revMap add:pix.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12210
                        map at:pix+1 put:(n_pix := revMap size - 1).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12211
                    ] ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12212
                        "/ mhmh - multiple pixels mapped to the same color
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12213
                        n_pix := (newColorArray indexOf:n_clr) - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12214
                        map at:pix+1 put:n_pix.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12215
                    ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12216
                ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12217
                newImage pixelAtX:x y:y put:n_pix.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12218
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12219
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12220
        revMap size == self colorMap size ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12221
            revMap = (0 to:revMap size-1) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12222
                ^ nil
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12223
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12224
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12225
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12226
        newImage colorMap:(MappedPalette withColors:newColorArray).
3905
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12227
    ].
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12228
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12229
    ^ newImage
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 12230
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 12231
    "Modified: / 30-01-2017 / 20:15:02 / stefan"
3905
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12232
!
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12233
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12234
withPixelFunctionApplied:pixelFunctionBlock
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12235
    "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
 12236
     on the pixel colors.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12237
     Notice: this method is very slow - either apply pixel values
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12238
     (#withPixelFunctionAppliedToPixels:) or redefine this method in
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12239
     a concrete subclass.
3860
571f1cd259f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3855
diff changeset
 12240
     (read `Beyond photography, by Gerard J. Holzmann;
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12241
           ISBM 0-13-074410-7)
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12242
     See blurred / oilPointed as examples ...)"
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12243
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12244
    |w  "{Class: SmallInteger }"
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12245
     h  "{Class: SmallInteger }"
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 12246
     newImage "newBits newBytesPerRow"|
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12247
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12248
    newImage := self species new.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12249
    newImage depth:self depth.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12250
    newImage width:width.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12251
    newImage height:height.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12252
"/    newBytesPerRow := ((width * self depth) + 7) // 8.
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12253
"/    newBits := ByteArray uninitializedNew:(newBytesPerRow * height).
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12254
    newImage createPixelStore. "/ bits:newBits.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12255
    newImage photometric:photometric.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12256
    newImage samplesPerPixel:samplesPerPixel.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12257
    newImage bitsPerSample:bitsPerSample.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12258
    newImage colorMap:colorMap copy.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12259
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12260
    w := width - 1.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12261
    h := height - 1.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12262
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12263
    0 to:h do:[:y |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12264
        0 to:w do:[:x |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12265
            newImage colorAtX:x y:y put:(pixelFunctionBlock
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12266
                                                value:self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12267
                                                value:(self colorAtX:x y:y)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12268
                                                value:x
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12269
                                                value:y)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12270
        ]
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12271
    ].
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12272
    ^ newImage
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12273
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12274
    "black out everything except for some rectangle:
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12275
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 12276
     |i black|
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12277
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12278
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12279
     i inspect.
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 12280
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 12281
     black := Color black.
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 12282
     (i withPixelFunctionApplied:[:oldImage :oldColor :x :y |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12283
                        ((x between:100 and:200)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12284
                        and:[y between:100 and:200]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12285
                            oldColor
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12286
                        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12287
                            black.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12288
                        ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12289
                     ]) inspect.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12290
    "
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12291
    "brighten a frame:
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12292
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12293
     |i black w h|
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12294
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12295
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12296
     i inspect.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12297
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12298
     w := i width.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12299
     h := i height.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12300
     (i withPixelFunctionApplied:[:oldImage :oldColor :x :y |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12301
                        ((x between:0 and:10)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12302
                        or:[(y between:0 and:10)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12303
                        or:[(x between:w-10 and:w)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12304
                        or:[y between:h-10 and:h]]]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12305
                            oldColor lightened nearestIn:i colorMap
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12306
                        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12307
                            oldColor.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12308
                        ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12309
                     ]) inspect.
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12310
    "
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12311
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12312
    "Modified: 24.4.1997 / 18:36:59 / cg"
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12313
!
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12314
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12315
withPixelFunctionAppliedToPixels:pixelFunctionBlock
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12316
    "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
 12317
     on the pixel values.
4296
240f73781089 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4226
diff changeset
 12318
     (read `Beyond photography, by Gerard J. Holzmann;
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12319
           ISBM 0-13-074410-7)
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12320
     See blurred / oilPointed as examples ...)"
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12321
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12322
    ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12323
        withPixelFunctionAppliedToPixels:pixelFunctionBlock
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12324
        in:(0@0 corner:width@height)
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12325
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12326
    "oil painting effect:
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12327
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12328
     |i w h|
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12329
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12330
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12331
     i inspect.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12332
     w := i width - 1.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12333
     h := i height - 1.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12334
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12335
                        |b p max xMin xMax yMin yMax|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12336
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12337
                        b := Bag identityNew:10.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12338
                        xMin := x-3 max:0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12339
                        xMax := x+3 min:w.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12340
                        yMin := y-3 max:0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12341
                        yMax := y+3 min:h.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12342
                        xMin to:xMax do:[:tx|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12343
                          yMin to:yMax do:[:ty|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12344
                            b add:(oldImage pixelAtX:tx y:ty)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12345
                          ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12346
                        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12347
                        max := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12348
                        b contents keysAndValuesDo:[:pixel :n |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12349
                            n > max ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12350
                                p := pixel.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12351
                                max := n
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12352
                            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12353
                        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12354
                        p
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12355
                     ]) inspect.
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12356
    "
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12357
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12358
    "fisheye effect:
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12359
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12360
     |i w h w2 h2 R white|
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12361
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12362
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12363
     i inspect.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12364
     w := i width - 1.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12365
     h := i height - 1.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12366
     w2 := w // 2.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12367
     h2 := h // 2.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12368
     R := w2.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12369
     white := i valueFromColor:Color white.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12370
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12371
                        |p r a nR nP nX nY|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12372
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12373
                        p := (x-w2)@(y-h2).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12374
                        r := p r.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12375
                        a := p theta.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12376
                        nR := r * r / R.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12377
                        nP := Point r:nR theta:a.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12378
                        nX := ((nP x+w2) rounded max:0) min:w.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12379
                        nY := ((nP y+h2) rounded max:0) min:h.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12380
                        (nX > w or:[nX < 0]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12381
                            white
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12382
                        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12383
                            (nY > h or:[nY < 0]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12384
                                white
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12385
                            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12386
                                oldImage pixelAtX:nX y:nY
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12387
                            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12388
                        ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12389
                     ]) inspect.
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12390
    "
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12391
    "fisheye effect:
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12392
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12393
     |i w h w2 h2 R white|
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12394
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12395
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12396
     i inspect.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12397
     w := i width - 1.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12398
     h := i height - 1.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12399
     w2 := w // 2.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12400
     h2 := h // 2.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12401
     R := w2.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12402
     white := i valueFromColor:Color white.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12403
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12404
                        |p r a nR nP nX nY|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12405
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12406
                        p := (x-w2)@(y-h2).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12407
                        r := p r.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12408
                        a := p theta.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12409
                        nR := r * r / R.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12410
                        nP := Point r:nR theta:a.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12411
                        nX := (nP x+w2) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12412
                        nY := (nP y+h2) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12413
                        (nX > w or:[nX < 0]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12414
                            white
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12415
                        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12416
                            (nY > h or:[nY < 0]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12417
                                white
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12418
                            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12419
                                oldImage pixelAtX:nX y:nY
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12420
                            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12421
                        ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12422
                     ]) inspect.
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12423
    "
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12424
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12425
    "Created: 24.4.1997 / 18:37:17 / cg"
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12426
    "Modified: 24.4.1997 / 18:40:02 / cg"
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12427
!
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12428
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12429
withPixelFunctionAppliedToPixels:pixelFunctionBlock in:aRectangle
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12430
    "return a new image from the old one, by applying a pixel processor
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12431
     on the pixel values.
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 12432
     (read `Beyond photography, by Gerard J. Holzmann;
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12433
           ISBM 0-13-074410-7)
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12434
     See blurred / oilPointed as examples ...)"
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12435
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 12436
    |newImage "newBits newBytesPerRow"|
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12437
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12438
    newImage := self species new.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12439
    newImage depth:self depth.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12440
    newImage width:width.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12441
    newImage height:height.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12442
"/    newBytesPerRow := ((width * self depth) + 7) // 8.
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12443
"/    newBits := ByteArray uninitializedNew:(newBytesPerRow * height).
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12444
    newImage createPixelStore. "/ bits:newBits
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12445
    newImage photometric:photometric.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12446
    newImage samplesPerPixel:samplesPerPixel.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12447
    newImage bitsPerSample:bitsPerSample.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12448
    newImage colorMap:colorMap copy.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12449
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12450
    self applyPixelValuesTo:pixelFunctionBlock in:aRectangle into:newImage.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12451
    ^ newImage
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12452
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12453
    "oil painting effect:
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12454
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12455
     |i w h|
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12456
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12457
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12458
     i inspect.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12459
     w := i width - 1.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12460
     h := i height - 1.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12461
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12462
                        |b p max xMin xMax yMin yMax|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12463
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12464
                        b := Bag identityNew:10.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12465
                        xMin := x-3 max:0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12466
                        xMax := x+3 min:w.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12467
                        yMin := y-3 max:0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12468
                        yMax := y+3 min:h.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12469
                        xMin to:xMax do:[:tx|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12470
                          yMin to:yMax do:[:ty|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12471
                            b add:(oldImage pixelAtX:tx y:ty)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12472
                          ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12473
                        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12474
                        max := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12475
                        b contents keysAndValuesDo:[:pixel :n |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12476
                            n > max ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12477
                                p := pixel.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12478
                                max := n
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12479
                            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12480
                        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12481
                        p
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12482
                     ]) inspect.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12483
    "
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12484
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12485
    "fisheye effect:
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12486
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 12487
     |i w h w2 h2 R white|
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12488
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12489
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12490
     i inspect.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12491
     w := i width - 1.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12492
     h := i height - 1.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12493
     w2 := w // 2.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12494
     h2 := h // 2.
1510
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12495
     R := w2.
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 12496
     white := i valueFromColor:Color white.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12497
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12498
                        |p r a nR nP nX nY|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12499
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12500
                        p := (x-w2)@(y-h2).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12501
                        r := p r.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12502
                        a := p theta.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12503
                        nR := r * r / R.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12504
                        nP := Point r:nR theta:a.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12505
                        nX := ((nP x+w2) rounded max:0) min:w.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12506
                        nY := ((nP y+h2) rounded max:0) min:h.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12507
                        (nX > w or:[nX < 0]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12508
                            white
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12509
                        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12510
                            (nY > h or:[nY < 0]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12511
                                white
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12512
                            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12513
                                oldImage pixelAtX:nX y:nY
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12514
                            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12515
                        ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12516
                     ]) inspect.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12517
    "
1510
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12518
    "fisheye effect:
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12519
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12520
     |i w h w2 h2 R white|
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12521
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12522
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
1510
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12523
     i inspect.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12524
     w := i width - 1.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12525
     h := i height - 1.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12526
     w2 := w // 2.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12527
     h2 := h // 2.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12528
     R := w2.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12529
     white := i valueFromColor:Color white.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12530
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12531
                        |p r a nR nP nX nY|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12532
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12533
                        p := (x-w2)@(y-h2).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12534
                        r := p r.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12535
                        a := p theta.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12536
                        nR := r * r / R.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12537
                        nP := Point r:nR theta:a.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12538
                        nX := (nP x+w2) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12539
                        nY := (nP y+h2) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12540
                        (nX > w or:[nX < 0]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12541
                            white
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12542
                        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12543
                            (nY > h or:[nY < 0]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12544
                                white
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12545
                            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12546
                                oldImage pixelAtX:nX y:nY
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12547
                            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12548
                        ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12549
                     ]) inspect.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12550
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12551
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12552
    "Created: 24.4.1997 / 18:37:17 / cg"
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12553
    "Modified: 24.4.1997 / 18:40:02 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12554
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12555
3870
8245e3f37feb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
 12556
!Image methodsFor:'initialization'!
8245e3f37feb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
 12557
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12558
createPixelStore
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12559
    |bytesPerRow|
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12560
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12561
    bytesPerRow := self bytesPerRow.
5643
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
 12562
    self bits:(ByteArray new:(bytesPerRow * self height)).
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
 12563
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
 12564
    "Modified: / 02-11-2010 / 20:57:11 / cg"
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12565
!
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12566
3871
a7867fb8d880 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3870
diff changeset
 12567
initialize
3870
8245e3f37feb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
 12568
    self photometric:(self class defaultPhotometric)
8245e3f37feb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
 12569
! !
8245e3f37feb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
 12570
8080
0e9dfadee86c Added `Grayscale` tab for inspector showing the image in gray.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8079
diff changeset
 12571
!Image methodsFor:'inspecting'!
0e9dfadee86c Added `Grayscale` tab for inspector showing the image in gray.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8079
diff changeset
 12572
0e9dfadee86c Added `Grayscale` tab for inspector showing the image in gray.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8079
diff changeset
 12573
inspector2TabImageGraySacel
0e9dfadee86c Added `Grayscale` tab for inspector showing the image in gray.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8079
diff changeset
 12574
    <inspector2Tab>
0e9dfadee86c Added `Grayscale` tab for inspector showing the image in gray.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8079
diff changeset
 12575
0e9dfadee86c Added `Grayscale` tab for inspector showing the image in gray.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8079
diff changeset
 12576
    ^ self newInspector2Tab
0e9dfadee86c Added `Grayscale` tab for inspector showing the image in gray.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8079
diff changeset
 12577
        label: 'Grayscale';
0e9dfadee86c Added `Grayscale` tab for inspector showing the image in gray.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8079
diff changeset
 12578
        priority: 45;
0e9dfadee86c Added `Grayscale` tab for inspector showing the image in gray.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8079
diff changeset
 12579
        view: ((HVScrollableView for:ImageView) image: (self asGrayImageDepth: self depth); 
0e9dfadee86c Added `Grayscale` tab for inspector showing the image in gray.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8079
diff changeset
 12580
        yourself)
0e9dfadee86c Added `Grayscale` tab for inspector showing the image in gray.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8079
diff changeset
 12581
0e9dfadee86c Added `Grayscale` tab for inspector showing the image in gray.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8079
diff changeset
 12582
    "Created: / 08-06-2017 / 14:32:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
0e9dfadee86c Added `Grayscale` tab for inspector showing the image in gray.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8079
diff changeset
 12583
! !
5037
2e515c9ee849 changed #valueFromColor:
Claus Gittinger <cg@exept.de>
parents: 4998
diff changeset
 12584
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12585
!Image methodsFor:'instance release'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12586
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12587
close
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12588
    "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
 12589
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12590
    deviceForm notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12591
        deviceForm destroy.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12592
        deviceForm := nil.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12593
    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12594
    monoDeviceForm notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12595
        monoDeviceForm destroy.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12596
        monoDeviceForm := nil.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12597
    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12598
    fullColorDeviceForm notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12599
        fullColorDeviceForm destroy.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12600
        fullColorDeviceForm := nil.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12601
    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12602
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12603
    device := nil.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12604
    mask notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12605
        mask close.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12606
    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12607
    Lobby unregister:self.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12608
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12609
    "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
 12610
    "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
 12611
!
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12612
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12613
release
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12614
    "release device resources"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12615
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12616
    device := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12617
    deviceForm := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12618
    monoDeviceForm := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12619
    fullColorDeviceForm := nil.
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
 12620
    mask notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12621
        mask release.
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
 12622
    ].
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
 12623
    Lobby unregister:self.
1746
72a583dd30bd must not forget super release
Claus Gittinger <cg@exept.de>
parents: 1739
diff changeset
 12624
    super release.
72a583dd30bd must not forget super release
Claus Gittinger <cg@exept.de>
parents: 1739
diff changeset
 12625
72a583dd30bd must not forget super release
Claus Gittinger <cg@exept.de>
parents: 1739
diff changeset
 12626
    "Modified: 11.6.1997 / 13:20:04 / cg"
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 12627
!
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 12628
4226
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12629
releaseFromDevice
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12630
    "release device resources"
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12631
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12632
    device := nil.
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12633
    deviceForm := nil.
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12634
    monoDeviceForm := nil.
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12635
    fullColorDeviceForm := nil.
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12636
7573
656c59bc93ad #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7565
diff changeset
 12637
4226
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12638
    "Modified: 16.1.1997 / 19:33:01 / cg"
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12639
!
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12640
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12641
restored
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12642
    "flush device specifics after a snapin or binary restore"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12643
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12644
    self release
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12645
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12646
2227
7aa9e2a8d321 added #edit - to open an image editor.
Claus Gittinger <cg@exept.de>
parents: 2212
diff changeset
 12647
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12648
!Image methodsFor:'obsolete'!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12649
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12650
applyPixelValuesTo:pixelFunctionBlock into:newImage in:aRectangle
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12651
    "helper for withPixelFunctionAppliedToValues:
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12652
     enumerate pixelValues and evaluate the block for each.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12653
     To be redefined by subclasses for better performance."
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12654
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12655
    ^ self applyPixelValuesTo:pixelFunctionBlock in:aRectangle into:newImage
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12656
!
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12657
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12658
magnifyBy:scale
5216
f7ec910cfce1 Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 5200
diff changeset
 12659
    <resource: #obsolete>
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12660
    "obsolete: has been renamed to magnifiedBy: for ST-80 compatibility
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12661
     and name consistency ..."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12662
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12663
    self obsoleteMethodWarning.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12664
    ^ self magnifiedBy:scale
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12665
! !
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12666
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12667
!Image methodsFor:'pixel copying'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12668
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12669
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
 12670
    "replace a rectangular area by pixels from another image.
7552
6d862b1829d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7551
diff changeset
 12671
     The source's colors must be present in the destination's
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 12672
     colorMap - otherwise, an error will be reported.
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12673
     Any mask is copied from the source.
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 12674
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12675
     WARNING:
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 12676
       This implementation is a very slow fallback general algorithm
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 12677
       (the loop over the source pixels is very slow).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12678
       If this method is used heavily, you may want to redefine it in
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12679
       concrete subclasses for the common case of of copying from an Image
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 12680
       with the same depth & palette.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12681
       If you do heavy image processing, specialized versions are even req'd
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 12682
       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
 12683
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12684
    |dX dY|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12685
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12686
    dX := srcX-dstX.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12687
    dY := srcY-dstY.
1248
6afcdec18986 commentary
Claus Gittinger <cg@exept.de>
parents: 1230
diff changeset
 12688
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12689
    ((photometric == anImage photometric)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12690
     and:[self bitsPerPixel == anImage bitsPerPixel
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12691
     and:[colorMap = anImage colorMap]]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12692
        "/ can loop over values
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12693
        anImage valuesFromX:srcX  y:srcY
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12694
                        toX:srcX+w-1 y:srcY+h-1
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12695
                         do:[:x :y :pixelValue |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12696
            self pixelAtX:x-dX y:y-dY put:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12697
        ]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12698
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12699
        "/ must loop over colors - horribly slow
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12700
        anImage colorsFromX:srcX  y:srcY
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12701
                        toX:srcX+w-1 y:srcY+h-1
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12702
                         do:[:x :y :clr |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12703
            self colorAtX:x-dX y:y-dY put:clr.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12704
        ]
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12705
    ].
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12706
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12707
    (mask isNil and:[anImage mask notNil]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12708
        "/ I have no mask; copied image has
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12709
        self createMask.
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12710
    ].
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12711
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12712
    mask notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12713
        anImage mask notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12714
            "/ both have a mask
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12715
            mask copyFrom:anImage mask x:srcX y:srcY toX:dstX y:dstY width:w height:h
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12716
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12717
            "/ I have a mask - copied image has not
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12718
            mask fillRectangleX:dstX y:dstY width:w height:h withValue:1
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12719
        ]
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12720
"/    ] ifFalse:[
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12721
"/        anImage mask notNil ifTrue:[
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12722
"/            "/ I have no mask; copied image has (already handled)
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12723
"/        ] ifFalse:[
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12724
"/            "/ none has a mask - nothing to do.
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12725
"/        ]
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12726
    ].
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12727
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12728
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12729
     |i1 i8 i4|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12730
7552
6d862b1829d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7551
diff changeset
 12731
     i8 := Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif'.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12732
     i8 inspect.
7552
6d862b1829d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7551
diff changeset
 12733
     i1 := Image fromFile:'../../libtool/bitmaps/SBrowser.xbm'.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12734
     i1 inspect.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12735
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12736
     i4 := Depth4Image fromImage:i8.
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 12737
     i4 copyFrom:i1 x:0 y:0 toX:20 y:20 width:20 height:20.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12738
     i4 inspect.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12739
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12740
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12741
    "Created: 20.9.1995 / 10:14:01 / claus"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12742
    "Modified: 20.9.1995 / 10:25:31 / claus"
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 12743
    "Modified: 21.6.1997 / 13:15:31 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12744
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12745
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12746
copyFrom:anImage x:srcX y:srcY toX:dstX y:dstY width:w height:h masked:maskedCopy
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12747
    "replace a rectangular area by pixels from another image.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12748
     The sources colors must be present in the destinations
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12749
     colorMap - otherwise, an error will be reported.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12750
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12751
     WARNING:
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12752
       This implementation is a very slow fallback general algorithm
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12753
       (the loop over the source pixels is very slow).
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12754
       If this method is used heavily, you may want to redefine it in
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12755
       concrete subclasses for the common case of of copying from an Image
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12756
       with the same depth & palette.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12757
       If you do heavy image processing, specialized versions are even req'd
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12758
       for other cases, rewriting the inner loops as inline C-code."
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12759
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12760
    maskedCopy ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12761
        self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12762
            copyMaskedFrom:anImage x:srcX y:srcY toX:dstX y:dstY width:w height:h
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12763
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12764
        self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12765
            copyFrom:anImage x:srcX y:srcY toX:dstX y:dstY width:w height:h
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12766
    ].
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12767
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12768
    "
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12769
     |i1 i8 i4|
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12770
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12771
     i8 := Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif'.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12772
     i8 inspect.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12773
     i1 := Image fromFile:'../../goodies/bitmaps/xbmBitmaps/TicTacToe.xbm'.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12774
     i1 inspect.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12775
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12776
     i4 := Depth4Image fromImage:i8.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12777
     i4 copyFrom:i1 x:0 y:0 toX:20 y:20 width:20 height:20.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12778
     i4 inspect.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12779
    "
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12780
!
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12781
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12782
copyMaskedFrom:anImage x:srcX y:srcY toX:dstX y:dstY width:w height:h
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12783
    "replace a rectangular area by pixels from another image.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12784
     The sources colors must be present in the destinations
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12785
     colorMap - otherwise, an error will be reported.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12786
     Only unmasked pixels are copied from the source.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12787
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12788
     WARNING:
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12789
       This implementation is a very slow fallback general algorithm
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12790
       (the loop over the source pixels is very slow).
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12791
       If this method is used heavily, you may want to redefine it in
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12792
       concrete subclasses for the common case of of copying from an Image
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12793
       with the same depth & palette.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12794
       If you do heavy image processing, specialized versions are even req'd
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12795
       for other cases, rewriting the inner loops as inline C-code."
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12796
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12797
    |dX dY|
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12798
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12799
    dX := srcX-dstX.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12800
    dY := srcY-dstY.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12801
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12802
    ((photometric == anImage photometric)
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12803
     and:[self bitsPerPixel == anImage bitsPerPixel
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12804
     and:[colorMap = anImage colorMap]]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12805
        "/ can loop over values
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12806
        anImage valuesFromX:srcX  y:srcY
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12807
                        toX:srcX+w-1 y:srcY+h-1
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12808
                         do:[:x :y :pixelValue |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12809
            (anImage maskAtX:x y:y) ~~ 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12810
                self pixelAtX:x-dX y:y-dY put:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12811
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12812
        ]
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12813
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12814
        "/ must loop over colors - horribly slow
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12815
        anImage colorsFromX:srcX  y:srcY
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12816
                        toX:srcX+w-1 y:srcY+h-1
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12817
                         do:[:x :y :clr |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12818
            (anImage maskAtX:x y:y) ~~ 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12819
                self colorAtX:x-dX y:y-dY put:clr.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12820
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12821
        ]
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12822
    ].
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12823
!
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12824
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12825
subImageIn:aRectangle
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12826
    "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
 12827
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12828
    ^ self class fromSubImage:self in:aRectangle
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12829
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12830
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12831
     |i|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12832
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 12833
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12834
     i inspect.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12835
     (i subImageIn:(300@160 corner:340@200)) inspect
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12836
    "
7551
a58984867d2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7537
diff changeset
 12837
    "
a58984867d2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7537
diff changeset
 12838
     |i|
a58984867d2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7537
diff changeset
 12839
a58984867d2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7537
diff changeset
 12840
     i := Image fromFile:'/Volumes/tmp/fillimage.ok.png'.
a58984867d2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7537
diff changeset
 12841
     i inspect.
a58984867d2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7537
diff changeset
 12842
     (i subImageIn:(0@0 corner:i width@i height)) inspect
a58984867d2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7537
diff changeset
 12843
    "
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12844
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12845
    "Created: 20.9.1995 / 01:24:20 / claus"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12846
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12847
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12848
!Image methodsFor:'pixel functions'!
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12849
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12850
computeBitsFromPixelFunction
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12851
    "compute the bits from the pixelfunction"
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12852
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 12853
    |bpr|
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12854
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12855
    bpr := self bytesPerRow.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12856
    bytes := ByteArray new:(bpr * height).
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12857
    0 to:height-1 do:[:y |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12858
        0 to:width-1 do:[:x |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12859
            self pixelAtX:x y:y put:(pixelFunction value:x value:y).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12860
        ]
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12861
    ].
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 12862
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 12863
    "Modified: / 31-01-2017 / 14:39:26 / stefan"
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12864
!
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12865
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12866
pixelFunction
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12867
    ^ pixelFunction
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12868
!
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12869
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12870
pixelFunction:aTwoArgFunction
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12871
    "set the pixel function. This is used to define a functional image,
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12872
     where pixel values are computed via a function instead of coming
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12873
     from a bits array (although a pixel array could also be seen as
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12874
     a pixel function).
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12875
     The pixelFunction will map (x E [0 .. width]) x (y E [0 .. height]) -> pixel"
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12876
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12877
    pixelFunction := aTwoArgFunction.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12878
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12879
    "
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12880
     |i|
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12881
     i := Depth1Image extent:256@256.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12882
     i pixelFunction:[:x :y | ((x // 16) bitXor:(y // 16)) odd asInteger].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12883
     i inspect.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12884
    "
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12885
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12886
    "
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12887
     |i|
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12888
     i := Depth8Image extent:256@256.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12889
     i photometric:#blackIs0.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12890
     i pixelFunction:[:x :y | x  ].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12891
     i inspect.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12892
    "
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12893
!
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12894
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12895
pixelFunction:aTwoArgFunction inX:xInterval y:yInterval
7373
61933c223183 added metaData instVar (for free use by image reader)
Claus Gittinger <cg@exept.de>
parents: 7363
diff changeset
 12896
    "set the pixel function and a viewport.
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12897
     This is used to define a functional image,
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12898
     where pixel values are computed via a function instead of coming
7373
61933c223183 added metaData instVar (for free use by image reader)
Claus Gittinger <cg@exept.de>
parents: 7363
diff changeset
 12899
     from a bits array.
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12900
     The pixelFunction will map (x E xInterval) x (y E yInterval) -> pixel"
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12901
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12902
    |sX sY tX tY|
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12903
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12904
    "/ intervals are typically 0..1
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12905
    sX := (xInterval stop - xInterval start) asFloat / width.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12906
    sY := (yInterval stop - yInterval start) asFloat / height.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12907
    tX := xInterval start.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12908
    tY := yInterval start.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12909
7373
61933c223183 added metaData instVar (for free use by image reader)
Claus Gittinger <cg@exept.de>
parents: 7363
diff changeset
 12910
    pixelFunction :=
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12911
        [:x :y |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12912
            aTwoArgFunction value:(x * sX + tX) value:(y * sY + tY)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12913
        ]
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12914
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12915
    "
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12916
     |i|
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12917
     i := Depth8Image extent:256@256.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12918
     i photometric:#blackIs0.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12919
     i pixelFunction:[:x :y | ((x@y) r * 255) truncated min:255] inX:(-1 to:1) y:(-1 to:1).
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12920
     i inspect.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12921
    "
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12922
! !
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12923
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12924
!Image methodsFor:'printing & storing'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12925
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12926
storeOn:aStream
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12927
    "append a printed representation of the receiver to aStream,
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12928
     from which a copy of it can be reconstructed."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12929
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12930
    |colors usedValues colorMapArray needBPS needSemi|
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12931
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12932
    needSemi := false.
7373
61933c223183 added metaData instVar (for free use by image reader)
Claus Gittinger <cg@exept.de>
parents: 7363
diff changeset
 12933
    aStream nextPutAll:('(%1 width:%2 height:%3'
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12934
                            bindWith:self class name
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12935
                            with:width
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12936
                            with:height).
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12937
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12938
    "/ avoiding some unneeded stuff here makes object files with many images a bit smaller.
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12939
    "/ no need for the photometric, if it's the default anyway
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12940
    photometric ~= self class defaultPhotometric ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12941
        (colorMap isNil or:[photometric ~~ #palette]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12942
            aStream nextPutAll:' photometric:('. photometric storeOn:aStream. aStream nextPut:$).
6912
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
 12943
            needSemi := false.
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12944
        ].
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12945
    ].
7349
361f96216120 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7292
diff changeset
 12946
    aStream nextPut:$).
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12947
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12948
    "/ no need to store bitPerSample/samplesPerPixel in all situations
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12949
    needBPS := true.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12950
7373
61933c223183 added metaData instVar (for free use by image reader)
Claus Gittinger <cg@exept.de>
parents: 7363
diff changeset
 12951
    self depth == 1
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12952
        ifTrue:[ needBPS := false ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12953
        ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12954
            ((photometric == #palette)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12955
                and:[ (bitsPerSample size == 1)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12956
                and:[ ((bitsPerSample at:1) == self depth)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12957
                and:[ samplesPerPixel == 1 ]]])
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12958
            ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12959
                needBPS := false.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12960
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12961
        ].
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12962
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12963
    needBPS ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12964
        needSemi ifTrue:[aStream nextPutAll:';'].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12965
        aStream nextPutAll:' bitsPerSample:('. bitsPerSample storeOn:aStream. aStream nextPutAll:')'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12966
        samplesPerPixel ~= bitsPerSample size ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12967
            aStream nextPutAll:'; samplesPerPixel:('. samplesPerPixel storeOn:aStream. aStream nextPutAll:')'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12968
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12969
        needSemi := true.
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12970
    ].
5533
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 12971
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 12972
    "/ assert that all bits are there...
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 12973
    "/ self assert:(self bits size) >= (self bytesPerRow * height).
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 12974
    "/ self bits:((ByteArray new:self bytesPerRow * height) replaceFrom:1 with:self bits).
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 12975
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12976
    needSemi ifTrue:[aStream nextPutAll:';'].
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12977
    aStream nextPutAll:' bits:(ByteArray fromPackedString:'. self bits asPackedString storeOn:aStream.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12978
    aStream nextPutAll:')'.
2068
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
 12979
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
 12980
    colorMap notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12981
        self depth <= 8 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12982
            "/ cut off unused colors ...
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12983
            usedValues := self usedValues.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12984
            colors := colorMap copyFrom:1 to:((usedValues max+1) min:colorMap size).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12985
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12986
            colorMapArray := OrderedCollection new.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12987
            colors do:[:clr| colorMapArray add:(clr redByte); add:(clr greenByte); add:(clr blueByte)].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12988
            aStream cr; spaces:12; nextPutAll:'colorMapFromArray:'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12989
            colorMapArray asByteArray storeOn:aStream.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12990
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12991
            aStream ct; spaces:12; nextPutAll:'colorMap:('.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12992
            colorMap storeOn:aStream.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12993
            aStream nextPutAll:')'
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12994
        ]
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12995
    ].
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
 12996
    mask notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12997
        aStream cr; spaces:12; nextPutAll:'mask:('.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12998
        mask storeOn:aStream.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12999
        aStream nextPutAll:')'.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13000
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13001
    aStream nextPutAll:'; yourself'
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
 13002
6912
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
 13003
    "Modified: / 22-08-1998 / 12:55:21 / cg"
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
 13004
    "Modified: / 01-09-2015 / 17:24:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 13005
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
 13006
48194c26a46c Initial revision
claus
parents:
diff changeset
 13007
!Image methodsFor:'private'!
48194c26a46c Initial revision
claus
parents:
diff changeset
 13008
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 13009
bestSupportedImageFormatFor:aDevice
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 13010
    "scan through the image formats as supported by aDevice,
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 13011
     and return the best to use when the receiver is to be represented
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 13012
     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
 13013
     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
 13014
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
 13015
    |bestDeviceDepth
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
 13016
     bestDeviceBitsPerPixel "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13017
     "maxDepth"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13018
     bestInfo maxInfo
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
 13019
     myDepth                "{ Class: SmallInteger }"
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
 13020
     maxBitsPerPixel        "{ Class: SmallInteger }"|
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 13021
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 13022
    myDepth := self bitsPerPixel.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 13023
    maxBitsPerPixel := 0.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 13024
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 13025
    aDevice supportedImageFormats do:[:entry |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13026
        |deviceImageDepth        "{ Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13027
         deviceImageBitsPerPixel "{ Class: SmallInteger }" |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13028
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13029
        deviceImageDepth := entry at:#depth.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13030
        deviceImageBitsPerPixel := entry at:#bitsPerPixel.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13031
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13032
        "/ for now, ignore all depth's which are neither 1 nor the
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13033
        "/ devices depth.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13034
        "/ (actually, many devices can handle other pixMap formats,
7659
01fe20eef85d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7640
diff changeset
 13035
        "/ but I don't know (yet) how to pass the correct color info
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13036
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13037
        ((deviceImageDepth == 1) or:[deviceImageDepth == aDevice depth]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13038
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13039
            deviceImageBitsPerPixel > maxBitsPerPixel ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13040
                maxInfo := entry.
2050
d1f21c75b5eb when asking a device for its supported pixmap formats,
Claus Gittinger <cg@exept.de>
parents: 2043
diff changeset
 13041
    "/            maxBitsPerPixel := deviceImageBitsPerPixel.
d1f21c75b5eb when asking a device for its supported pixmap formats,
Claus Gittinger <cg@exept.de>
parents: 2043
diff changeset
 13042
    "/            maxDepth := deviceImageDepth.
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13043
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13044
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13045
            deviceImageDepth >= myDepth ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13046
                deviceImageDepth == myDepth ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13047
                    "/ take the better one ...
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13048
                    (bestDeviceDepth isNil
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13049
                     or:[(bestDeviceBitsPerPixel ~~ bestDeviceDepth)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13050
                        and:[deviceImageDepth == deviceImageBitsPerPixel]]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13051
                        bestInfo := entry.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13052
                        bestDeviceDepth := deviceImageDepth.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13053
                        bestDeviceBitsPerPixel := deviceImageBitsPerPixel.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13054
                    ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13055
                ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13056
                    "/ take the next-larger depth
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13057
                    (bestDeviceDepth isNil
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13058
                     or:[deviceImageBitsPerPixel < bestDeviceBitsPerPixel]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13059
                        bestInfo := entry.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13060
                        bestDeviceDepth := deviceImageDepth.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13061
                        bestDeviceBitsPerPixel := deviceImageBitsPerPixel.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13062
                    ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13063
                ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13064
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13065
        ].
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 13066
    ].
851
c9511f8945ce fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents: 841
diff changeset
 13067
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 13068
    bestDeviceDepth isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13069
        maxBitsPerPixel == 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13070
            "/
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13071
            "/ oops - nothing appropriate
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13072
            "/
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13073
            maxInfo notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13074
                ^ maxInfo
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13075
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13076
            bestDeviceDepth := bestDeviceBitsPerPixel := aDevice depth.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13077
            bestInfo := IdentityDictionary new.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13078
            bestInfo at:#depth put:bestDeviceDepth.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13079
            bestInfo at:#bitsPerPixel put:bestDeviceBitsPerPixel.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13080
            bestInfo at:#padding put:32.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13081
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13082
            bestInfo := maxInfo.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13083
        ]
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 13084
    ].
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
 13085
    ^ bestInfo
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
 13086
2050
d1f21c75b5eb when asking a device for its supported pixmap formats,
Claus Gittinger <cg@exept.de>
parents: 2043
diff changeset
 13087
    "Modified: / 7.2.1998 / 11:23:24 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13088
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13089
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13090
colormapFromImage:anImage
7242
bf3a75233d55 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7230
diff changeset
 13091
    "setup the receiver's colormap from another image.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13092
     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
 13093
     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
 13094
     for fromImage:/fromSubImake:"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13095
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 13096
    self colormapFromImage:anImage photometric:nil
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 13097
!
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 13098
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 13099
colormapFromImage:anImage photometric:photometricOrNil
7242
bf3a75233d55 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7230
diff changeset
 13100
    "setup the receiver's colormap from another image.
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 13101
     Color precision may be lost, if conversion is from a higher depth
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 13102
     image. This does not convert any pixel values; it is  non-public helper
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 13103
     for fromImage:/fromSubImake:"
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 13104
2447
5b3d802d602b allow Image fromImage with rgb source-image and palette receiver
Claus Gittinger <cg@exept.de>
parents: 2415
diff changeset
 13105
    |usedColors|
5b3d802d602b allow Image fromImage with rgb source-image and palette receiver
Claus Gittinger <cg@exept.de>
parents: 2415
diff changeset
 13106
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13107
    samplesPerPixel == 3 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13108
        photometric := photometricOrNil ? #rgb
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13109
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13110
        photometricOrNil isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13111
            photometric := anImage photometric.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13112
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13113
            photometric := photometricOrNil.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13114
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13115
        photometric == #palette ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13116
            self setColorMap:(anImage colorMap copy).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13117
            "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13118
             must generate/compress the colormap, if source image has higher depth
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13119
             than myself.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13120
            "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13121
            (colorMap isNil
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13122
            or:[anImage bitsPerPixel > self bitsPerPixel]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13123
                "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13124
                 get used colors are extracted into our colorMap
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13125
                 (the at-put below will set the pixelValue according the
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13126
                 new colorIndex
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13127
                "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13128
                self setColorMap:(anImage usedColors asArray).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13129
                colorMap size > (1 bitShift:self bitsPerPixel) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13130
                    'Image [warning]: possibly too many colors in image' errorPrintCR
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13131
                ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13132
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13133
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13134
            (photometric == #blackIs0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13135
            or:[ photometric == #whiteIs0 ]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13136
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13137
                usedColors := anImage usedColors asArray.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13138
                usedColors size > (1 bitShift:self bitsPerPixel) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13139
                    'Image [warning]: possibly too many colors in image' errorPrintCR.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13140
                    usedColors := usedColors copyTo:(1 bitShift:self bitsPerPixel).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13141
                ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13142
                self setColorMap:usedColors.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13143
                photometric := #palette
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13144
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13145
        ]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13146
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13147
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13148
    "Created: 20.9.1995 / 00:58:42 / claus"
1175
5595569cfbd3 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 1170
diff changeset
 13149
    "Modified: 10.1.1997 / 17:52:21 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13150
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13151
7637
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 13152
fromDeviceForm:aForm maskForm:aMaskFormOrNil
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 13153
    device := aForm device.
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 13154
    self assert:device notNil.
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 13155
    photometric := aForm photometric.
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 13156
    deviceForm := aForm.
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 13157
    width := aForm width.
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 13158
    height := aForm height.
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 13159
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 13160
    aMaskFormOrNil notNil ifTrue:[
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 13161
        mask := Image fromDeviceForm:aMaskFormOrNil maskForm:nil.
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 13162
    ].
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 13163
!
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 13164
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13165
greyByteMapForRange:range
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13166
    "return a collection to map from pixelValues to greyLevels
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13167
     in the range 0..range.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13168
     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
 13169
     The values are rounded towards the nearest pixel."
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13170
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
 13171
    |d clr val greyMap r
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
 13172
     n "{ Class: SmallInteger }"|
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 13173
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 13174
    r := range.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 13175
    r == 256 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13176
        r := 255
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13177
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13178
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13179
    photometric == #palette ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13180
        n := colorMap size.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13181
        greyMap := ByteArray new:n.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13182
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13183
        1 to:n do:[:i |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13184
            (clr := colorMap at:i) isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13185
                "/ an unused color
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13186
                val := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13187
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13188
                val := (r * clr brightness) rounded
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13189
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13190
            greyMap at:i put:val
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13191
        ].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13192
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13193
        d := self bitsPerPixel.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13194
        n := 1 bitShift:d.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13195
        n >= 4096 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13196
            self error:'size not supported - too large'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13197
            ^ nil
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13198
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13199
        greyMap := ByteArray new:n.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13200
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13201
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13202
        photometric == #rgb ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13203
            1 to:n do:[:i |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13204
                greyMap at:i put:(r * (self colorFromValue:i-1) brightness) rounded
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13205
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13206
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13207
            1 to:n do:[:i |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13208
                greyMap at:i put:(r / (n-1) * (i-1)) rounded
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13209
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13210
            photometric == #blackIs0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13211
                "/ we are done
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13212
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13213
                photometric == #whiteIs0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13214
                    greyMap reverse
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13215
                ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13216
                    self error:'invalid format'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13217
                    ^ nil
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13218
                ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13219
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13220
        ].
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13221
    ].
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 13222
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13223
    ^ greyMap
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13224
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13225
    "
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 13226
     Depth8Image new greyByteMapForRange:256
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 13227
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 13228
     Depth8Image new greyByteMapForRange:64
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 13229
     Depth4Image new greyByteMapForRange:64
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 13230
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 13231
     Depth4Image new greyByteMapForRange:1
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13232
    "
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13233
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13234
    "Created: 8.6.1996 / 08:34:14 / cg"
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
 13235
    "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
 13236
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13237
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13238
greyMapForRange:range
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13239
    "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
 13240
     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
 13241
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
 13242
    |d r clr val
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 13243
     n "{Class: SmallInteger }"
1927
d1bbdf03e5a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1919
diff changeset
 13244
     n2 "{Class: SmallInteger }"
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 13245
     greyArray|
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13246
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13247
    d := self bitsPerPixel.
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13248
    n := 1 bitShift:d.
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13249
    n >= 4096 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13250
        self error:'size not supported - too large'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13251
        ^ nil
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13252
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13253
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 13254
    greyArray := Array new:n.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13255
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13256
    photometric == #palette ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13257
        n2 := colorMap size.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13258
        1 to:n2 do:[:i |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13259
            (clr := colorMap at:i) isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13260
                "/ an unused color
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13261
                val := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13262
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13263
                val := range * clr brightness
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13264
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13265
            greyArray at:i put:val
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13266
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13267
        n2 < n ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13268
            greyArray from:n2+1 to:n put:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13269
        ]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13270
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13271
        photometric == #rgb ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13272
            1 to:n do:[:i |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13273
                greyArray at:i put:(range * (self colorFromValue:(i-1)) brightness)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13274
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13275
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13276
            r := range asFloat.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13277
            1 to:n do:[:i |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13278
                greyArray at:i put:(r / (n-1) * (i-1))
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13279
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13280
            photometric == #blackIs0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13281
                "/ we are done
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13282
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13283
                photometric == #whiteIs0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13284
                    greyArray reverse
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13285
                ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13286
                    self error:'invalid format'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13287
                    ^ nil
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13288
                ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13289
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13290
        ]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13291
    ].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 13292
    ^ greyArray
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13293
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13294
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13295
     Depth8Image new greyMapForRange:64
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13296
     Depth4Image new greyMapForRange:64
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13297
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 13298
     Depth16Image new greyMapForRange:1
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13299
     Depth4Image new greyMapForRange:1
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 13300
     Depth2Image new greyMapForRange:1
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 13301
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 13302
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
 13303
    "Modified: 1.3.1997 / 15:48:49 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13304
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13305
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13306
magnifyRowFrom:srcBytes offset:srcStart
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13307
          into:dstBytes offset:dstStart factor:mX
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13308
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13309
    "magnify a single pixel row - can only magnify by integer factors,
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13310
     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
 13311
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13312
    ^ self subclassResponsibility
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13313
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13314
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13315
makeDeviceGrayPixmapOn:aDevice depth:depth fromArray:bits
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13316
    "given the bits of a grey/color bitmap, 8-bit padded and
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13317
     pixels interpreted as greyValues, 0 is black,
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13318
     create a device form for it"
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13319
7755
75f5eba88e77 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7689
diff changeset
 13320
    |f gcId|
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13321
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 13322
    f := Form width:width height:height depth:depth onDevice:aDevice.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13323
    f isNil ifTrue:[^ nil].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13324
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13325
    f bits:bits.
7755
75f5eba88e77 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7689
diff changeset
 13326
    gcId := f initGC.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13327
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13328
    (aDevice blackpixel ~~ 0) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13329
        "/ have to invert bits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13330
        f function:#copyInverted
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13331
    ].
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13332
    aDevice
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13333
        drawBits:bits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13334
        depth:depth
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13335
        padding:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13336
        width:width height:height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13337
        x:0 y:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13338
        into:(f id)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13339
        x:0 y:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13340
        width:width height:height
7755
75f5eba88e77 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7689
diff changeset
 13341
        with:gcId.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13342
    ^ f
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13343
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13344
    "Created: 10.6.1996 / 20:10:31 / cg"
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13345
!
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13346
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13347
makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13348
    "given the bits of a monochrome bitmap, 8-bit padded and
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13349
     0-bits as black, create a device form for it"
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13350
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
 13351
"/    monoBits invert.
4769
0cabcf1481a0 Use Form class>>#width:height:fromArray:onDevice: instead of obsolete
Stefan Vogel <sv@exept.de>
parents: 4762
diff changeset
 13352
    ^ (Form width:width height:height fromArray:monoBits onDevice:aDevice)
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13353
        colorMap:(Array with:Color black with:Color white).
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13354
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13355
    "Created: 10.6.1996 / 20:18:09 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
 13356
    "Modified: 17.4.1997 / 01:07:38 / cg"
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13357
!
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13358
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13359
makeDevicePixmapOn:aDevice depth:depth fromArray:bits
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13360
    "given the bits of a grey/color bitmap, 8-bit padded and
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13361
     pixels interpreted as in the devices colormap,
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13362
     create a device form for it"
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13363
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13364
    |f|
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13365
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 13366
    f := Form width:width height:height depth:depth onDevice:aDevice.
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13367
    f isNil ifTrue:[^ nil].
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13368
    f bits:bits.
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13369
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13370
    aDevice
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13371
        drawBits:bits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13372
        depth:depth
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13373
        padding:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13374
        width:width height:height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13375
        x:0 y:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13376
        into:(f id)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13377
        x:0 y:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13378
        width:width height:height
7755
75f5eba88e77 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7689
diff changeset
 13379
        with:(f initGC).
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13380
    ^ f
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13381
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13382
    "Created: 10.6.1996 / 17:56:08 / cg"
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13383
    "Modified: 10.6.1996 / 20:11:27 / cg"
5237
e28aca881988 repairPhotometric
Claus Gittinger <cg@exept.de>
parents: 5235
diff changeset
 13384
!
e28aca881988 repairPhotometric
Claus Gittinger <cg@exept.de>
parents: 5235
diff changeset
 13385
e28aca881988 repairPhotometric
Claus Gittinger <cg@exept.de>
parents: 5235
diff changeset
 13386
repairPhotometric
e28aca881988 repairPhotometric
Claus Gittinger <cg@exept.de>
parents: 5235
diff changeset
 13387
    "/ kludge: repair a 'should not happen' situation...
e28aca881988 repairPhotometric
Claus Gittinger <cg@exept.de>
parents: 5235
diff changeset
 13388
    photometric isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13389
        (self depth == 24 and:[ bitsPerSample size == 3 ]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13390
            photometric := #rgb
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13391
        ].
5237
e28aca881988 repairPhotometric
Claus Gittinger <cg@exept.de>
parents: 5235
diff changeset
 13392
    ].
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
 13393
! !
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 13394
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13395
!Image methodsFor:'queries'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13396
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13397
alphaBitsOf:pixel
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13398
    "if the receiver is an rgb-image:
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13399
     return the alpha component of a pixelValue as integer 0..maxAlphaValue.
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13400
     MaxAlphaValue is of course the largest integer representable by the number
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13401
     of alpha bits i.e. (1 bitShift:bitsAlpha)-1.
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13402
     This has to be redefined by subclasses."
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13403
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13404
    |redBits greenBits blueBits alphaBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13405
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13406
    samplesPerPixel >= 4 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13407
        redBits := bitsPerSample at:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13408
        greenBits := bitsPerSample at:2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13409
        blueBits := bitsPerSample at:3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13410
        alphaBits := bitsPerSample at:4.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13411
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13412
        ^ (pixel bitShift:(redBits + greenBits + blueBits) negated)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13413
           bitAnd:(1 bitShift:alphaBits)-1
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13414
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13415
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13416
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13417
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13418
    "Created: 8.6.1996 / 09:44:51 / cg"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13419
    "Modified: 10.6.1996 / 14:59:05 / cg"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13420
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13421
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13422
alphaMaskForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13423
    "return the mask used with translation from pixelValues to alphaBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13424
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13425
    |alphaBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13426
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13427
    samplesPerPixel >= 4 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13428
        alphaBits := bitsPerSample at:4.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13429
        ^ (1 bitShift:alphaBits)-1
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13430
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13431
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13432
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13433
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13434
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13435
alphaShiftForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13436
    "return the shift amount used with translation from pixelValues to alphaBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13437
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13438
    |redBits greenBits blueBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13439
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13440
    samplesPerPixel >= 3 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13441
        redBits := bitsPerSample at:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13442
        greenBits := bitsPerSample at:2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13443
        blueBits := bitsPerSample at:3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13444
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13445
        ^ (greenBits + blueBits + redBits) negated
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13446
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13447
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13448
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13449
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13450
3813
662c6386828e ascentOn:
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
 13451
ascentOn:aGC
662c6386828e ascentOn:
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
 13452
    "I will not draw myself above the baseline"
662c6386828e ascentOn:
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
 13453
662c6386828e ascentOn:
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
 13454
    ^ 0
662c6386828e ascentOn:
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
 13455
!
662c6386828e ascentOn:
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
 13456
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13457
averageColor
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13458
    "return the average color of the image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13459
     This usually only makes sense for textures and patterns
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13460
     (i.e. to compute shadow & light colors for viewBackgrounds).
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 13461
     Notice that for the above purpose, it is usually ok to process
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13462
     a subImage - i.e. use Image>>averageColorIn: on a smaller rectangle"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13463
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13464
    ^ self averageColorIn:(0@0 corner:(width-1)@(height-1))
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13465
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13466
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13467
averageColorIn:aRectangle
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13468
    "return the images average color in an area.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13469
     The implementation below is slow - so you may want to
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13470
     create tuned versions for DepthXImage if you plan to do
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13471
     heavy image processing ...
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13472
     (also, creating tuned versions of the enumeration messages helps a lot)"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13473
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13474
    |x0 "{ Class:SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13475
     y0 "{ Class:SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13476
     x1 "{ Class:SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13477
     y1 "{ Class:SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13478
     sumRed sumGreen sumBlue n|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13479
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13480
    sumRed := sumGreen := sumBlue := 0.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13481
    y0 := aRectangle top.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13482
    y1 := aRectangle bottom.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13483
    x0 := aRectangle left.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13484
    x1 := aRectangle right.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13485
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13486
    n := (x1 - x0 + 1) * (y1 - y0 + 1).
3761
44b96cd84bb8 ignore masked pixels when computing the average
Claus Gittinger <cg@exept.de>
parents: 3760
diff changeset
 13487
    mask isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13488
        self colorsFromX:x0 y:y0 toX:x1 y:y1 do:[:x :y :colorAtXY |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13489
            sumRed := sumRed + colorAtXY red.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13490
            sumGreen := sumGreen + colorAtXY green.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13491
            sumBlue := sumBlue + colorAtXY blue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13492
        ].
3761
44b96cd84bb8 ignore masked pixels when computing the average
Claus Gittinger <cg@exept.de>
parents: 3760
diff changeset
 13493
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13494
        "/ masked pixels are not counted.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13495
        self colorsFromX:x0 y:y0 toX:x1 y:y1 do:[:x :y :colorAtXY |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13496
            (mask pixelAtX:x y:y) == 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13497
                n := n - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13498
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13499
                sumRed := sumRed + colorAtXY red.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13500
                sumGreen := sumGreen + colorAtXY green.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13501
                sumBlue := sumBlue + colorAtXY blue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13502
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13503
        ].
3761
44b96cd84bb8 ignore masked pixels when computing the average
Claus Gittinger <cg@exept.de>
parents: 3760
diff changeset
 13504
    ].
44b96cd84bb8 ignore masked pixels when computing the average
Claus Gittinger <cg@exept.de>
parents: 3760
diff changeset
 13505
    n == 0 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13506
        "/ all masked
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13507
        ^ Color black
3761
44b96cd84bb8 ignore masked pixels when computing the average
Claus Gittinger <cg@exept.de>
parents: 3760
diff changeset
 13508
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13509
    ^ Color red:(sumRed / n) green:(sumGreen / n) blue:(sumBlue / n)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13510
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13511
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13512
bitsPerPixel
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13513
    "return the number of bits per pixel"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13514
5926
95dab34aeea2 changed: #bitsPerPixel
Stefan Vogel <sv@exept.de>
parents: 5919
diff changeset
 13515
    ^ bitsPerSample sum
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13516
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13517
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13518
bitsPerRow
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13519
    "return the number of bits in one scanline of the image"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13520
3868
e47cf114c824 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
 13521
    ^ width * (self bitsPerPixel).
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13522
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13523
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13524
blackComponentOfCMYK:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13525
    "if the receiver is a cmyk-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13526
     return the black component scaled to a percentage (0 .. 100) of a pixelValue."
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13527
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13528
    samplesPerPixel == 4 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13529
        "/ assume that the cyan bits are the leftMost bits (cmyk)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13530
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 13531
        (#[8 8 8 8] isSameSequenceAs:bitsPerSample) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13532
            ^ 100.0 / 255 * (pixel bitAnd:16rFF)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13533
        ]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13534
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13535
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13536
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13537
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 13538
    "Modified (format): / 31-01-2017 / 13:15:23 / stefan"
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13539
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13540
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13541
blueBitsOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13542
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13543
     return the blue bits of a pixelValue as integer 0..maxBlueValue.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13544
     MaxGreenValue is of course the largest integer representable by the number
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13545
     of blue bits i.e. (1 bitShift:bitsBlue)-1.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13546
     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
 13547
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13548
    |blueBits|
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13549
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13550
    samplesPerPixel >= 3 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13551
        blueBits := bitsPerSample at:3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13552
        ^ 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
 13553
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13554
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13555
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13556
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13557
    "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
 13558
    "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
 13559
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13560
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13561
blueComponentOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13562
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13563
     return the blue component scaled to a percentage (0 .. 100) of a pixelValue.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13564
     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
 13565
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 13566
    |blueBits  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 13567
     s         "{ Class: SmallInteger }"|
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13568
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13569
    samplesPerPixel >= 3 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13570
        "/ assume that the red bits are the leftMost bits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13571
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13572
        blueBits := bitsPerSample at:3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13573
        blueBits == 0 ifTrue:[^ 0].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13574
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13575
        s := (1 bitShift:blueBits) - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13576
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13577
        ^ 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
 13578
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13579
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13580
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13581
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13582
    "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
 13583
    "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
 13584
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13585
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13586
blueMaskForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13587
    "return the mask used with translation from pixelValues to blueBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13588
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13589
    |blueBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13590
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13591
    samplesPerPixel >= 3 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13592
        blueBits := bitsPerSample at:3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13593
        ^ (1 bitShift:blueBits)-1
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13594
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13595
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13596
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13597
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13598
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13599
blueShiftForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13600
    "return the shift amount used with translation from pixelValues to blueBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13601
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13602
    samplesPerPixel >= 3 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13603
        ^ 0
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13604
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13605
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13606
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13607
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13608
680
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 13609
bounds
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 13610
    "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
 13611
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 13612
    ^ 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
 13613
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 13614
    "Created: 13.5.1996 / 10:27:06 / cg"
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 13615
!
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 13616
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13617
brightness
6755
cee1206f74db class: Image
Claus Gittinger <cg@exept.de>
parents: 6653
diff changeset
 13618
    "return the (average) brightness of the image as number in 0..1.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13619
     This usually only makes sense for textures and patterns
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13620
     (i.e. to compute shadow & light colors for viewBackgrounds).
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 13621
     Notice that for the above purpose, only a subimage is inspected here"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13622
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13623
    ^ (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
 13624
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13625
    "Modified: 8.6.1996 / 08:46:46 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13626
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13627
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13628
bytesPerRow
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13629
    "return the number of bytes in one scanline of the image"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13630
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13631
    |bitsPerRow bytesPerRow|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13632
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13633
    bitsPerRow := width * (self bitsPerPixel).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13634
    bytesPerRow := bitsPerRow // 8.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13635
    ((bitsPerRow \\ 8) ~~ 0) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13636
        bytesPerRow := bytesPerRow + 1
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13637
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13638
    ^ bytesPerRow
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13639
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13640
1993
b3cf63f64e15 added query for padded bytesPerLine
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
 13641
bytesPerRowPaddedTo:padding
b3cf63f64e15 added query for padded bytesPerLine
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
 13642
    "return the number of bytes in one scanline of the image,
b3cf63f64e15 added query for padded bytesPerLine
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
 13643
     if scanlines are to be padded to padding-bits."
b3cf63f64e15 added query for padded bytesPerLine
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
 13644
2005
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
 13645
    ^ self class
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13646
        bytesPerRowForWidth:width depth:(self bitsPerPixel) padding:padding
1993
b3cf63f64e15 added query for padded bytesPerLine
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
 13647
!
b3cf63f64e15 added query for padded bytesPerLine
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
 13648
1935
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 13649
center
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 13650
    "for compatibility with GC protocol - return the centerPoint"
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 13651
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 13652
    ^ (width // 2) @ (height // 2)
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 13653
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 13654
    "Created: 22.10.1997 / 23:52:40 / cg"
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 13655
!
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 13656
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13657
colorFromValue:pixelValue
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13658
    "given a pixel value, return the corresponding color.
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13659
     Pixel values start with 0.
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13660
     The implementation below is generic and slow
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13661
     - this method is typically redefined in subclasses."
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13662
5126
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
 13663
    |p maxPixel clr r g b c m y k a
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
 13664
     numRedBits numGreenBits numBlueBits numAlphaBits|
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 13665
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 13666
    p := photometric.
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 13667
    p isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13668
        colorMap notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13669
            p := #palette
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13670
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13671
            "/ 'Image [warning]: no photometric - assume greyscale' infoPrintCR
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13672
            p := #blackIs0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13673
        ]
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 13674
    ].
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 13675
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 13676
    p == #blackIs0 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13677
        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13678
        ^ Color gray:(pixelValue * (100 / maxPixel)).
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13679
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13680
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 13681
    p == #whiteIs0 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13682
        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13683
        ^ 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
 13684
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13685
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 13686
    p == #palette ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13687
        pixelValue >= colorMap size ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13688
            ^ Color black
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13689
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13690
        clr := colorMap at:(pixelValue + 1).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13691
        clr isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13692
            ^ Color black.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13693
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13694
        ^ clr.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13695
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13696
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 13697
    p == #rgb ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13698
        r := self redBitsOf:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13699
        g := self greenBitsOf:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13700
        b := self blueBitsOf:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13701
        "/ scale...
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13702
        numRedBits := bitsPerSample at:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13703
        numGreenBits := bitsPerSample at:2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13704
        numBlueBits := bitsPerSample at:3.
7595
c77d718d3d94 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7573
diff changeset
 13705
        (r ~~ 0) ifTrue:[ r := 100 / ((1 bitShift:numRedBits) - 1) * r].
c77d718d3d94 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7573
diff changeset
 13706
        (g ~~ 0) ifTrue:[ g := 100 / ((1 bitShift:numGreenBits) - 1) * g].
c77d718d3d94 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7573
diff changeset
 13707
        (b ~~ 0) ifTrue:[ b := 100 / ((1 bitShift:numBlueBits) - 1) * b].
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13708
        ^ Color redPercent:r greenPercent:g bluePercent:b
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 13709
    ].
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 13710
7123
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 13711
    ((p == #rgba) or:[p == #argb]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13712
        r := self redBitsOf:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13713
        g := self greenBitsOf:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13714
        b := self blueBitsOf:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13715
        a := self alphaBitsOf:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13716
        "/ scale...
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13717
        numRedBits := bitsPerSample at:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13718
        numGreenBits := bitsPerSample at:2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13719
        numBlueBits := bitsPerSample at:3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13720
        numAlphaBits := bitsPerSample at:4.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13721
        (r == 0) ifFalse:[ r := (100 / ((1 bitShift:numRedBits)-1) * r)].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13722
        (g == 0) ifFalse:[ g := (100 / ((1 bitShift:numGreenBits)-1) * g)].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13723
        (b == 0) ifFalse:[ b := (100 / ((1 bitShift:numBlueBits)-1) * b)].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13724
        (a == 0) ifFalse:[ a := (100 / ((1 bitShift:numAlphaBits)-1) * a)].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13725
        ^ Color redPercent:r greenPercent:g bluePercent:b alphaPercent:a
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13726
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13727
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13728
    p == #cmyk ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13729
        c := self cyanComponentOfCMYK:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13730
        m := self magentaComponentOfCMYK:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13731
        y := self yellowComponentOfCMYK:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13732
        k := self blackComponentOfCMYK:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13733
        ^ Color cyan:c magenta:m yellow:y black:k.
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13734
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13735
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13736
    p == #cmy ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13737
        c := self cyanComponentOfCMY:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13738
        m := self magentaComponentOfCMY:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13739
        y := self yellowComponentOfCMY:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13740
        ^ Color cyan:c magenta:m yellow:y.
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13741
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13742
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13743
    self error:'invalid (unsupported) photometric'
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13744
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 13745
    "Created: / 08-06-1996 / 08:46:18 / cg"
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 13746
    "Modified: / 06-06-2007 / 11:21:57 / cg"
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13747
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13748
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13749
cyanComponentOfCMY:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13750
    "if the receiver is a cmy-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13751
     return the cyan component scaled to a percentage (0 .. 100) of a pixelValue."
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13752
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13753
    samplesPerPixel == 3 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13754
        "/ assume that the cyan bits are the leftMost bits (cmy)
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 13755
        (#[8 8 8] isSameSequenceAs:bitsPerSample)ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13756
            ^ 100.0 / 255 * ((pixel bitShift:-16) bitAnd:16rFF)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13757
        ]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13758
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13759
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13760
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13761
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 13762
    "Modified (format): / 31-01-2017 / 13:15:56 / stefan"
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13763
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13764
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13765
cyanComponentOfCMYK:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13766
    "if the receiver is a cmyk-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13767
     return the cyan component scaled to a percentage (0 .. 100) of a pixelValue."
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13768
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13769
    samplesPerPixel == 4 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13770
        "/ assume that the cyan bits are the leftMost bits (cmyk)
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 13771
        (#[8 8 8 8] isSameSequenceAs:bitsPerSample)ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13772
            ^ 100.0 / 255 * ((pixel bitShift:-24) bitAnd:16rFF)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13773
        ]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13774
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13775
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13776
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13777
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 13778
    "Modified: / 31-01-2017 / 13:16:14 / stefan"
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13779
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13780
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13781
greenBitsOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13782
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13783
     return the green bits of a pixelValue as integer 0..maxGreenValue.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13784
     MaxGreenValue is of course the largest integer representable by the number
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13785
     of green bits i.e. (1 bitShift:bitsGreen)-1.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13786
     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
 13787
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13788
    |blueBits greenBits|
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13789
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13790
    samplesPerPixel >= 3 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13791
        greenBits := bitsPerSample at:2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13792
        blueBits := bitsPerSample at:3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13793
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13794
        ^ (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
 13795
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13796
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13797
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13798
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13799
    "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
 13800
    "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
 13801
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13802
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13803
greenComponentOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13804
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13805
     return the green component scaled to a percentage (0..100) of a pixelValue.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13806
     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
 13807
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 13808
    |greenBits "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 13809
     blueBits  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 13810
     s         "{ Class: SmallInteger }"|
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13811
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13812
    samplesPerPixel >= 3 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13813
        "/ assume that the red bits are the leftMost bits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13814
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13815
        greenBits := bitsPerSample at:2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13816
        greenBits == 0 ifTrue:[^ 0].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13817
        blueBits := bitsPerSample at:3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13818
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13819
        s := (1 bitShift:greenBits) - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13820
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13821
        ^ 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
 13822
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13823
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13824
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13825
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13826
    "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
 13827
    "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
 13828
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13829
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13830
greenMaskForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13831
    "return the mask used with translation from pixelValues to greenBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13832
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13833
    |greenBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13834
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13835
    samplesPerPixel >= 3 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13836
        greenBits := bitsPerSample at:2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13837
        ^ (1 bitShift:greenBits)-1
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13838
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13839
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13840
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13841
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13842
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13843
greenShiftForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13844
    "return the shift amount used with translation from pixelValues to greenBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13845
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 13846
    |greenBits|
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13847
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13848
    samplesPerPixel >= 3 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13849
        greenBits := bitsPerSample at:3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13850
        ^ greenBits negated
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13851
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13852
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13853
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13854
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13855
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13856
heightOn:aGC
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13857
    "return my height, if displayed on aGC;
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13858
     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
 13859
     return the pixel-height"
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13860
680
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 13861
    ^ height
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13862
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13863
    "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
 13864
    "Modified: 13.5.1996 / 10:26:36 / cg"
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13865
!
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13866
3700
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 13867
isDithered
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 13868
    "for compatibility with color protocol"
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 13869
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 13870
    ^ false
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 13871
!
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 13872
3507
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 13873
isGrayscaleImage
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 13874
    ^ (photometric ~= #palette)
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 13875
      and:[photometric ~= #rgb]
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 13876
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 13877
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 13878
    "Created: 22.4.1997 / 14:12:02 / cg"
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 13879
!
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 13880
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13881
isImage
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13882
    "return true, if the receiver is some kind of image;
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13883
     true is returned here - the method is redefined from Object."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13884
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13885
    ^ true
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13886
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13887
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13888
isImageOrForm
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13889
    "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
 13890
     true is returned here - the method is redefined from Object."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13891
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13892
    ^ true
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13893
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13894
1630
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 13895
isMask
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 13896
    ^ false
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 13897
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 13898
    "Created: 22.4.1997 / 14:12:02 / cg"
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 13899
!
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 13900
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13901
magentaComponentOfCMY:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13902
    "if the receiver is a cmy-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13903
     return the magenta component scaled to a percentage (0 .. 100) of a pixelValue."
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13904
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13905
    samplesPerPixel == 3 ifTrue:[
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 13906
        (#[8 8 8] isSameSequenceAs:bitsPerSample)ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13907
            ^ 100.0 / 255 * ((pixel bitShift:-8) bitAnd:16rFF)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13908
        ]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13909
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13910
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13911
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13912
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 13913
    "Modified (format): / 31-01-2017 / 13:19:06 / stefan"
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13914
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13915
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13916
magentaComponentOfCMYK:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13917
    "if the receiver is a cmyk-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13918
     return the magenta component scaled to a percentage (0 .. 100) of a pixelValue."
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13919
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13920
    samplesPerPixel == 4 ifTrue:[
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 13921
        (#[8 8 8 8] isSameSequenceAs:bitsPerSample)ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13922
            ^ 100.0 / 255 * ((pixel bitShift:-16) bitAnd:16rFF)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13923
        ]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13924
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13925
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13926
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13927
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 13928
    "Modified (format): / 31-01-2017 / 13:19:11 / stefan"
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13929
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13930
7596
9e63984bd73f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7595
diff changeset
 13931
nColorsUsed
9e63984bd73f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7595
diff changeset
 13932
    ^ self realUsedValues size
9e63984bd73f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7595
diff changeset
 13933
!
9e63984bd73f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7595
diff changeset
 13934
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 13935
pixelArraySpecies
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 13936
    "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
 13937
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 13938
    self depth <= 8 ifTrue:[^ ByteArray].
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 13939
    "/ (d := self depth) <= 8 ifTrue:[^ ByteArray].
6648
dc88bb5f9231 class: Image
Claus Gittinger <cg@exept.de>
parents: 6624
diff changeset
 13940
    "/ d <= 16 ifTrue:[^ WordArray].
dc88bb5f9231 class: Image
Claus Gittinger <cg@exept.de>
parents: 6624
diff changeset
 13941
    "/ ^ IntegerArray
dc88bb5f9231 class: Image
Claus Gittinger <cg@exept.de>
parents: 6624
diff changeset
 13942
    ^ Array
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 13943
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 13944
    "Modified: / 31-01-2017 / 14:52:42 / stefan"
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 13945
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 13946
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13947
realColorMap
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13948
    "return a collection usable as a real colormap of the image.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13949
     For palette images, this is the internal colormap;
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13950
     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
 13951
     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
 13952
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13953
    |d nEntries "{ Class: SmallInteger }"
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13954
     colorArray|
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13955
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13956
    photometric == #palette ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13957
        ^ colorMap asArray
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13958
    ].
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13959
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13960
    d := self depth.
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13961
    d > 12 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13962
        self error:'deep palette images not supported'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13963
        ^ nil.
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13964
    ].
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13965
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13966
    nEntries := 1 bitShift:d.
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13967
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13968
    colorArray := Array new:nEntries.
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13969
    1 to:nEntries do:[:idx |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13970
        colorArray at:idx put:(self colorFromValue:(idx-1)).
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13971
    ].
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13972
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13973
    ^ colorArray
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13974
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13975
    "Created: 11.7.1996 / 20:20:35 / cg"
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13976
    "Modified: 11.7.1996 / 20:49:21 / cg"
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13977
!
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13978
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13979
realUsedColors
3964
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 13980
    "return a collection of colors which are really used in the receiver.
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 13981
     This goes through the pixels and adds up colors as present in the image
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 13982
     (as opposed to #usedColors, which looks at the colorMap if present)"
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13983
6379
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
 13984
    ^ self realUsedValues collect:[:pixel | self colorFromValue:pixel] as:Set
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13985
!
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13986
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13987
realUsedValues
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13988
    "return a collection of color values used in the receiver.
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 13989
     Notice that the interpretation of the pixels depends on the photometric
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13990
     of the image.
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13991
     This is a general and therefore slow implementation; subclasses
3964
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 13992
     may want to redefine this method for more performance.
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 13993
     This goes through the pixels and adds up colors as present in the image
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 13994
     (as opposed to #usedColors, which looks at the colorMap if present)"
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13995
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13996
    |set last|
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13997
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13998
    set := IdentitySet new.
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13999
    self valuesFromX:0 y:0 toX:(self width-1) y:(self height-1) do:[:x :y :pixel |
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 14000
        pixel ~~ last ifTrue:[
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 14001
            set add:pixel.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 14002
            last := pixel.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 14003
        ]
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 14004
    ].
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 14005
    ^ set
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 14006
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 14007
    "
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 14008
     (Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') usedValues
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 14009
     (Image fromFile:'libtool/bitmaps/SBrowser.xbm') usedValues
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 14010
    "
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 14011
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 14012
    "Modified: / 29.7.1998 / 21:29:44 / cg"
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 14013
!
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 14014
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 14015
redBitsOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 14016
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14017
     return the red component of a pixelValue as integer 0..maxRedValue.
5126
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
 14018
     MaxRedValue is the largest integer representable by the number
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14019
     of red bits i.e. (1 bitShift:bitsRed)-1.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 14020
     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
 14021
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 14022
    |redBits greenBits blueBits|
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 14023
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 14024
    samplesPerPixel >= 3 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14025
        redBits := bitsPerSample at:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14026
        greenBits := bitsPerSample at:2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14027
        blueBits := bitsPerSample at:3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14028
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14029
        ^ (pixel bitShift:(greenBits + blueBits) negated)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14030
           bitAnd:(1 bitShift:redBits)-1
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 14031
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 14032
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 14033
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 14034
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 14035
    "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
 14036
    "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
 14037
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 14038
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 14039
redComponentOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 14040
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14041
     return the red component scaled to a percentage (0..100) of a pixelValue.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 14042
     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
 14043
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 14044
    |redBits   "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 14045
     greenBits "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 14046
     blueBits  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 14047
     s         "{ Class: SmallInteger }"|
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 14048
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 14049
    samplesPerPixel >= 3 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14050
        "/ assume that the red bits are the leftMost bits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14051
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14052
        redBits := bitsPerSample at:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14053
        redBits == 0 ifTrue:[^ 0].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14054
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14055
        greenBits := bitsPerSample at:2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14056
        blueBits := bitsPerSample at:3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14057
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14058
        s := (1 bitShift:redBits) - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14059
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14060
        ^ 100.0 / s *
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14061
          ((pixel bitShift:(greenBits + blueBits) negated)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14062
           bitAnd:(1 bitShift:redBits)-1)
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 14063
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 14064
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 14065
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 14066
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 14067
    "Created: 8.6.1996 / 08:45:30 / cg"
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 14068
    "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
 14069
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 14070
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 14071
redMaskForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 14072
    "return the mask used with translation from pixelValues to redBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 14073
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 14074
    |redBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 14075
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 14076
    samplesPerPixel >= 3 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14077
        redBits := bitsPerSample at:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14078
        ^ (1 bitShift:redBits)-1
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 14079
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 14080
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 14081
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 14082
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 14083
    "Created: 8.6.1996 / 09:44:51 / cg"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 14084
    "Modified: 10.6.1996 / 14:59:05 / cg"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 14085
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 14086
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 14087
redShiftForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 14088
    "return the shift amount used with translation from pixelValues to redBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 14089
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 14090
    |greenBits blueBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 14091
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 14092
    samplesPerPixel >= 3 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14093
        greenBits := bitsPerSample at:2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14094
        blueBits := bitsPerSample at:3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14095
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14096
        ^ (greenBits + blueBits) negated
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 14097
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 14098
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 14099
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 14100
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 14101
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14102
rgbFromValue:pixelValue
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14103
    "given a pixel value, return the corresponding 24bit rgbValue (rrggbb, red is MSB).
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14104
     Pixel value is in 0..2^depth - 1.
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14105
     The implementation below is generic and slow
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14106
     - this method is typically redefined in subclasses."
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14107
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14108
    |p maxPixel clr r g b c m y k|
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14109
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14110
    p := photometric.
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14111
    p isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14112
        colorMap notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14113
            p := #palette
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14114
        ] ifFalse:[
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14115
"/            'Image [warning]: no photometric - assume greyscale' infoPrintCR
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14116
            p := #blackIs0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14117
        ]
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14118
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14119
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14120
    p == #blackIs0 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14121
        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14122
        b := pixelValue * 255 // maxPixel.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14123
        ^ (((b bitShift:8) bitOr:b) bitShift:8) bitOr:b
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14124
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14125
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14126
    p == #whiteIs0 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14127
        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14128
        b := 255 - (pixelValue * 255 // maxPixel).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14129
        ^ (((b bitShift:8) bitOr:b) bitShift:8) bitOr:b
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14130
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14131
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14132
    p == #palette ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14133
        pixelValue >= colorMap size ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14134
            ^ 0 "/ black
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14135
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14136
        clr := colorMap at:(pixelValue + 1).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14137
        clr isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14138
            ^ 0 "/ black
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14139
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14140
        ^ clr rgbValue.
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14141
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14142
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14143
    p == #rgb ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14144
        r := self redBitsOf:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14145
        g := self greenBitsOf:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14146
        b := self blueBitsOf:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14147
        "/ must scale to byte value...
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14148
        r := r bitShift:(8 - (bitsPerSample at:1)).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14149
        g := g bitShift:(8 - (bitsPerSample at:2)).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14150
        b := b bitShift:(8 - (bitsPerSample at:3)).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14151
        ^ (((r bitShift:8) bitOr:g) bitShift:8) bitOr:b
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14152
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14153
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14154
    p == #cmyk ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14155
        c := self cyanComponentOfCMYK:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14156
        m := self magentaComponentOfCMYK:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14157
        y := self yellowComponentOfCMYK:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14158
        k := self blackComponentOfCMYK:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14159
        ^ (Color cyan:c magenta:m yellow:y black:k) rgbValue.
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14160
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14161
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14162
    p == #cmy ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14163
        c := self cyanComponentOfCMY:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14164
        m := self magentaComponentOfCMY:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14165
        y := self yellowComponentOfCMY:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14166
        ^ (Color cyan:c magenta:m yellow:y) rgbValue.
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14167
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14168
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14169
    self error:'invalid (unsupported) photometric'
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14170
!
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14171
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14172
usedColors
3964
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 14173
    "return a collection of colors used in the receiver.
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 14174
     This looks at the colorMap only if present.
6896
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 14175
     (as opposed to #realUsedColors, which goes through the pixels of the bitmap)"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14176
2311
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 14177
    |colors|
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 14178
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 14179
    colors := self usedColorsMax:4096.
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 14180
    colors isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14181
        self error:'too many colors in image'.
2311
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 14182
    ].
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 14183
    ^ colors
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 14184
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 14185
    "
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 14186
     (Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') usedColors
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 14187
     (Image fromFile:'libtool/bitmaps/SBrowser.xbm') usedColors
2311
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 14188
    "
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 14189
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 14190
    "Modified: / 7.9.1998 / 17:56:12 / cg"
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 14191
!
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 14192
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 14193
usedColorsMax:nMax
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 14194
    "return a collection of colors used in the receiver;
3964
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 14195
     This looks at the colorMap only if present
6896
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 14196
     (as opposed to #realUsedColors, which goes through the pixels of the bitmap).
3964
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 14197
     However, stop looking for more, if more than nMax colors have been found
2311
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 14198
     (useful when searching rgb images)."
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 14199
2199
ac56b54c59a5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2185
diff changeset
 14200
    |usedValues max colors|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14201
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 14202
    photometric == #rgb ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14203
        usedValues := IdentitySet new.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14204
        self valuesFromX:0 y:0 toX:(width-1) y:(height-1)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14205
          do:[:x :y :pixel |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14206
            usedValues add:pixel.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14207
            usedValues size > nMax ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14208
                "/ too many to be returned here (think of the mass of
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14209
                "/ data to be returned by a 24bit image ... ;-)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14210
                ^ nil
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14211
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14212
        ].
7595
c77d718d3d94 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7573
diff changeset
 14213
"/        colors := usedValues collect:[:pixel | self colorFromValue:pixel].
c77d718d3d94 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7573
diff changeset
 14214
        "/ this code is slightly faster (but wrong for 16-bit images)...
c77d718d3d94 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7573
diff changeset
 14215
        colors := usedValues collect:[:pixel | 
c77d718d3d94 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7573
diff changeset
 14216
                    |r g b|
c77d718d3d94 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7573
diff changeset
 14217
                    r := self redBitsOf:pixel.
c77d718d3d94 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7573
diff changeset
 14218
                    g := self greenBitsOf:pixel.
c77d718d3d94 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7573
diff changeset
 14219
                    b := self blueBitsOf:pixel.
c77d718d3d94 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7573
diff changeset
 14220
                    "/ must scale to byte value...
c77d718d3d94 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7573
diff changeset
 14221
                    r := r bitShift:(8 - (bitsPerSample at:1)).
c77d718d3d94 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7573
diff changeset
 14222
                    g := g bitShift:(8 - (bitsPerSample at:2)).
c77d718d3d94 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7573
diff changeset
 14223
                    b := b bitShift:(8 - (bitsPerSample at:3)).
c77d718d3d94 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7573
diff changeset
 14224
                    Color redByte:r greenByte:g blueByte:b
c77d718d3d94 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7573
diff changeset
 14225
                 ].
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14226
        ^ colors.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 14227
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 14228
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14229
    usedValues := self usedValues asArray.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 14230
    photometric == #palette ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14231
        colors := usedValues collect:[:val | (colorMap at:val+1 ifAbsent:[Color black])] as:Set.
2199
ac56b54c59a5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2185
diff changeset
 14232
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14233
        "/ (photometric == #blackIs0 or:[photometric == #whiteIs0])
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14234
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14235
        max := (1 bitShift:self depth) - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14236
        colors :=  usedValues collect:[:val | (Color gray:(100 * val / max ))] as:Set.
6037
eea2343b0b1e Refactoring:
Stefan Vogel <sv@exept.de>
parents: 5956
diff changeset
 14237
    ].
eea2343b0b1e Refactoring:
Stefan Vogel <sv@exept.de>
parents: 5956
diff changeset
 14238
    ^ colors
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14239
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14240
    "
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 14241
     (Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') usedColors
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 14242
     (Image fromFile:'libtool/bitmaps/SBrowser.xbm') usedColors
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14243
    "
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
 14244
2311
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 14245
    "Created: / 7.9.1998 / 17:54:17 / cg"
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 14246
    "Modified: / 7.9.1998 / 17:56:21 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14247
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14248
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14249
usedValues
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14250
    "return a collection of color values used in the receiver.
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 14251
     Notice that the interpretation of the pixels depends on the photometric
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14252
     of the image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14253
     This is a general and therefore slow implementation; subclasses
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14254
     may want to redefine this method for more performance."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14255
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 14256
    ^ self realUsedValues
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14257
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14258
    "
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 14259
     (Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') usedValues
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 14260
     (Image fromFile:'lib tool/bitmaps/SBrowser.xbm') usedValues
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14261
    "
2206
8bf0549762b8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2205
diff changeset
 14262
8bf0549762b8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2205
diff changeset
 14263
    "Modified: / 29.7.1998 / 21:29:44 / cg"
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 14264
!
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 14265
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14266
valueFromColor:color
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14267
    "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
 14268
     Non-representable colors return nil."
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14269
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 14270
    |pixel maxPixel redBits greenBits blueBits alphaBits r g b a|
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14271
5051
492727d3e5f3 oops valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 5037
diff changeset
 14272
    color colorId notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14273
        color == Color noColor ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14274
            ^ nil "/ mask
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14275
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14276
        color device isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14277
            ^ color colorId
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14278
        ]
5051
492727d3e5f3 oops valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 5037
diff changeset
 14279
    ].
5037
2e515c9ee849 changed #valueFromColor:
Claus Gittinger <cg@exept.de>
parents: 4998
diff changeset
 14280
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14281
    photometric == #whiteIs0 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14282
        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14283
        ^ maxPixel - (color brightness * maxPixel) rounded.
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14284
    ].
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14285
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14286
    photometric == #blackIs0 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14287
        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14288
        ^ (color brightness * maxPixel) rounded.
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14289
    ].
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14290
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14291
    photometric == #palette ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14292
        colorMap isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14293
            "/ same as blackIs0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14294
            maxPixel := (1 bitShift:self bitsPerPixel) - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14295
            ^ (color brightness * maxPixel) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14296
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14297
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14298
        pixel := colorMap indexOf:color.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14299
        pixel == 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14300
            "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14301
             the color is not in the images colormap
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14302
            "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14303
            ^ nil
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14304
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14305
        ^ pixel - 1
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14306
    ].
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14307
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14308
    photometric == #rgb ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14309
        samplesPerPixel >= 3 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14310
            redBits := bitsPerSample at:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14311
            greenBits := bitsPerSample at:2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14312
            blueBits := bitsPerSample at:3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14313
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14314
            "/ map r/g/b to 0..255
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14315
            r := (color red / 100.0 * ((1 bitShift:redBits)-1)) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14316
            g := (color green / 100.0 * ((1 bitShift:greenBits)-1)) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14317
            b := (color blue / 100.0 * ((1 bitShift:blueBits)-1)) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14318
            pixel := (((r bitShift:greenBits) + g) bitShift:blueBits) + b.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14319
            ^ pixel
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14320
        ]
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14321
    ].
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14322
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 14323
    photometric == #rgba ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14324
        samplesPerPixel >= 4 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14325
            redBits := bitsPerSample at:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14326
            greenBits := bitsPerSample at:2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14327
            blueBits := bitsPerSample at:3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14328
            alphaBits := bitsPerSample at:4.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14329
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14330
            "/ map r/g/b/a to 0..255
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14331
            r := (color red / 100.0 * ((1 bitShift:redBits)-1)) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14332
            g := (color green / 100.0 * ((1 bitShift:greenBits)-1)) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14333
            b := (color blue / 100.0 * ((1 bitShift:blueBits)-1)) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14334
            a := (color alpha * ((1 bitShift:alphaBits)-1)) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14335
            pixel := (((((a bitShift:redBits) + r) bitShift:greenBits) + g) bitShift:blueBits) + b.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14336
            ^ pixel
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14337
        ]
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 14338
    ].
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
 14339
    ImageErrorSignal raiseErrorString:'format not supported'.
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14340
    ^ nil
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14341
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 14342
    "Modified: / 06-06-2007 / 11:26:15 / cg"
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14343
!
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14344
4858
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14345
valueFromRGB:rgb
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14346
    "given a color, return the corresponding pixel value.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14347
     Non-representable colors return nil."
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14348
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 14349
    |pixel redBits greenBits blueBits r g b a|
4858
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14350
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14351
    r := rgb bitAnd:16rFF.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14352
    g := (rgb bitShift:-8) bitAnd:16rFF.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14353
    b := (rgb bitShift:-16) bitAnd:16rFF.
7123
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 14354
    a := 255.
4858
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14355
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14356
"/    photometric == #whiteIs0 ifTrue:[
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14357
"/        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14358
"/        ^ maxPixel - (color brightness * maxPixel) rounded.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14359
"/    ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14360
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14361
"/    photometric == #blackIs0 ifTrue:[
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14362
"/        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14363
"/        ^ (color brightness * maxPixel) rounded.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14364
"/    ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14365
"/
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14366
"/    photometric == #palette ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14367
"/        colorMap isNil ifTrue:[
4858
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14368
"/            "/ same as blackIs0
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14369
"/            maxPixel := (1 bitShift:self bitsPerPixel) - 1.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14370
"/            ^ (color brightness * maxPixel) rounded.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14371
"/        ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14372
"/
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14373
"/        pixel := colorMap indexOf:color.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14374
"/        pixel == 0 ifTrue:[
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14375
"/            "
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14376
"/             the color is not in the images colormap
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14377
"/            "
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14378
"/            ^ nil
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14379
"/        ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14380
"/        ^ pixel - 1
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14381
"/    ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14382
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14383
    photometric == #rgb ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14384
        samplesPerPixel >= 3 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14385
            "/ r,g,b  b at low end
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14386
            redBits := bitsPerSample at:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14387
            greenBits := bitsPerSample at:2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14388
            blueBits := bitsPerSample at:3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14389
            pixel := (((r bitShift:greenBits) + g) bitShift:blueBits) + b.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14390
            ^ pixel
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14391
        ]
4858
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14392
    ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14393
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14394
    photometric == #rgba ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14395
        samplesPerPixel >= 4 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14396
            "/ a,r,g,b  b at low end
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14397
            redBits := bitsPerSample at:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14398
            greenBits := bitsPerSample at:2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14399
            blueBits := bitsPerSample at:3.
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 14400
"/            alphaBits := bitsPerSample at:4.
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14401
            pixel := (((((a bitShift:redBits) + r) bitShift:greenBits) + g) bitShift:blueBits) + b.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14402
            ^ pixel
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14403
        ]
4858
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14404
    ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14405
    ImageErrorSignal raiseErrorString:'format not supported'.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14406
    ^ nil
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14407
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14408
    "Created: / 15-01-2008 / 15:55:08 / cg"
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 14409
    "Modified: / 31-01-2017 / 14:45:00 / stefan"
4858
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14410
!
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14411
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14412
valueFromRedBits:redBits greenBits:greenBits blueBits:blueBits
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14413
    "given a rgb bits, each in 0..maxXXXValue (i.e. according to
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14414
     r/g/b channels number of bits, return the corresponding pixel value.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14415
     For now, only useful with RGB images"
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14416
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14417
    |pixel numGreenBits numBlueBits|
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14418
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14419
    photometric == #rgb ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14420
        samplesPerPixel >= 3 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14421
            numGreenBits := bitsPerSample at:2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14422
            numBlueBits := bitsPerSample at:3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14423
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14424
            pixel := (((redBits bitShift:numGreenBits) + greenBits) bitShift:numBlueBits) + blueBits.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14425
            ^ pixel
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14426
        ]
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14427
    ].
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14428
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14429
    ImageErrorSignal raiseErrorString:'format not supported'.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14430
    ^ nil
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14431
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14432
    "Modified: / 30.9.1998 / 22:03:50 / cg"
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14433
!
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14434
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 14435
widthOn:aGC
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 14436
    "return my width, if displayed on aGC;
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 14437
     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
 14438
     return the pixel-width"
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 14439
680
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 14440
    ^ width
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 14441
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 14442
    "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
 14443
    "Modified: 13.5.1996 / 10:26:42 / cg"
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14444
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14445
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14446
yellowComponentOfCMY:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14447
    "if the receiver is a cmy-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14448
     return the yellow component scaled to a percentage (0 .. 100) of a pixelValue."
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14449
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14450
    samplesPerPixel == 3 ifTrue:[
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 14451
        (#[8 8 8] isSameSequenceAs:bitsPerSample)ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14452
            ^ 100.0 / 255 * (pixel bitAnd:16rFF)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14453
        ]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14454
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14455
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14456
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14457
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14458
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 14459
    "Modified (format): / 31-01-2017 / 13:18:47 / stefan"
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14460
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14461
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14462
yellowComponentOfCMYK:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14463
    "if the receiver is a cmyk-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14464
     return the yellow component scaled to a percentage (0 .. 100) of a pixelValue."
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14465
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14466
    samplesPerPixel == 4 ifTrue:[
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 14467
        (#[8 8 8 8] isSameSequenceAs:bitsPerSample)ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14468
            ^ 100.0 / 255 * ((pixel bitShift:-8) bitAnd:16rFF)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14469
        ]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14470
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14471
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14472
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14473
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 14474
    "Modified: / 31-01-2017 / 13:19:00 / stefan"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14475
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14476
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14477
!Image methodsFor:'saving on file'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14478
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14479
saveOn:aFileName
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14480
    "save the image in aFileName. The suffix of the filename controls the format.
3913
25e103c84773 comments
Claus Gittinger <cg@exept.de>
parents: 3912
diff changeset
 14481
     Currently, not all formats may be supported
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 14482
     (see ImageReader subclasses implementing save:onFile:).
3913
25e103c84773 comments
Claus Gittinger <cg@exept.de>
parents: 3912
diff changeset
 14483
     May raise a signal, if the image cannot be written by the reader."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14484
7173
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14485
    ^ self saveOn:aFileName quality:nil
1175
5595569cfbd3 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 1170
diff changeset
 14486
1385
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 14487
    "
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 14488
     |image|
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 14489
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14490
     image := Image fromFile:'goodies/bitmaps/RCube.tiff'.
1385
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 14491
     image saveOn:'myImage.tiff'.
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 14492
     image saveOn:'myImage.xbm'.
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 14493
     image saveOn:'myImage.xpm'.
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 14494
     image saveOn:'myImage.xwd'.
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 14495
    "
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 14496
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
 14497
    "Modified: 30.6.1997 / 22:06:34 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 14498
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 14499
7173
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14500
saveOn:aFileName quality:qualityPercentOrNil
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14501
    "save the image in aFileName. The suffix of the filename controls the format.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14502
     Currently, not all formats may be supported
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14503
     (see ImageReader subclasses implementing save:onFile:).
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14504
     May raise a signal, if the image cannot be written by the reader."
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14505
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14506
    |suffix readerClass|
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14507
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14508
    "/
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14509
    "/ from the extension, get the imageReader class
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14510
    "/ (which should know how to write images as well)
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14511
    "/
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14512
    suffix := aFileName asFilename suffix.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14513
    readerClass := MIMETypes imageReaderForSuffix:suffix.
7373
61933c223183 added metaData instVar (for free use by image reader)
Claus Gittinger <cg@exept.de>
parents: 7363
diff changeset
 14514
    readerClass isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14515
        "/
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14516
        "/ no known extension - could ask user for the format here.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14517
        "/ currently default to tiff format.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14518
        "/
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14519
        readerClass := self class defaultImageFileWriter.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14520
        'Image [warning]: unknown extension - cannot figure out format - using default (',readerClass name,')' errorPrintCR.
7173
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14521
    ].
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14522
    ^ self saveOn:aFileName quality:qualityPercentOrNil using:readerClass
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14523
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14524
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14525
    "
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14526
     |image|
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14527
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14528
     image := Image fromFile:'goodies/bitmaps/RCube.tiff'.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14529
     image saveOn:'myImage.tiff'.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14530
     image saveOn:'myImage.xbm'.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14531
     image saveOn:'myImage.xpm'.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14532
     image saveOn:'myImage.xwd'.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14533
    "
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14534
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14535
    "Modified: 30.6.1997 / 22:06:34 / cg"
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14536
!
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14537
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14538
saveOn:aFileName quality:qualityPercentOrNil using:readerClass
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14539
    "save the receiver using the representation class
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14540
     (which is usually a concrete subclasses of ImageReader).
3913
25e103c84773 comments
Claus Gittinger <cg@exept.de>
parents: 3912
diff changeset
 14541
     May raise a signal, if the image cannot be written by the reader."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14542
7173
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14543
    ^ readerClass save:self onFile:aFileName quality:qualityPercentOrNil
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14544
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14545
    "
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 14546
     |anImage|
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 14547
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14548
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 14549
     anImage saveOn:'myImage.tiff' using:TIFFReader.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14550
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14551
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14552
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14553
     |anImage|
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14554
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14555
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 14556
     anImage saveOn:'myImage.xbm' using:XBMReader.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14557
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14558
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14559
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14560
     |anImage|
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14561
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14562
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14563
     Image cannotRepresentImageSignal handle:[:ex |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14564
        self warn:'cannot save the image in this format'
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14565
     ] do:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14566
        anImage saveOn:'myImage.xbm' using:XBMReader.
7173
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14567
     ]
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14568
    "
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14569
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14570
    "
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14571
     |anImage|
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14572
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14573
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14574
     anImage saveOn:'myImage.xpm' using:XPMReader.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14575
    "
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14576
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14577
    "
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14578
     |anImage|
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14579
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14580
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14581
     anImage saveOn:'myImage.gif' using:GIFReader.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14582
    "
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14583
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14584
    "Modified: 10.4.1997 / 17:49:26 / cg"
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14585
!
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14586
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14587
saveOn:aFileName using:readerClass
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14588
    "save the receiver using the representation class
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14589
     (which is usually a concrete subclasses of ImageReader).
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14590
     May raise a signal, if the image cannot be written by the reader."
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14591
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14592
    ^ readerClass save:self onFile:aFileName quality:nil
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14593
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14594
    "
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14595
     |anImage|
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14596
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14597
     anImage := Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif'.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14598
     anImage saveOn:'myImage.tiff' using:TIFFReader.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14599
     (Depth24Image fromImage:anImage) saveOn:'myImage.jpg' using:JPEGReader.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14600
     anImage saveOn:'myImage50.tiff' quality:50 using:TIFFReader.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14601
     (Depth24Image fromImage:anImage) saveOn:'myImage50.jpg' quality:50 using:JPEGReader.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14602
    "
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14603
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14604
    "
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14605
     |anImage|
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14606
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14607
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14608
     anImage saveOn:'myImage.xbm' using:XBMReader.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14609
    "
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14610
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14611
    "
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14612
     |anImage|
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14613
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14614
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14615
     Image cannotRepresentImageSignal handle:[:ex |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14616
        self warn:'cannot save the image in this format'
7173
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14617
     ] do:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14618
        anImage saveOn:'myImage.xbm' using:XBMReader.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14619
     ]
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14620
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14621
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14622
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14623
     |anImage|
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14624
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14625
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 14626
     anImage saveOn:'myImage.xpm' using:XPMReader.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14627
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14628
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14629
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14630
     |anImage|
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14631
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14632
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 14633
     anImage saveOn:'myImage.gif' using:GIFReader.
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 14634
    "
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 14635
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14636
    "Modified: 10.4.1997 / 17:49:26 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 14637
! !
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14638
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14639
!Image methodsFor:'screen capture'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14640
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14641
from:aDrawable in:aRectangle
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14642
    "read an image from aDrawable.
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14643
     This may be a device Form, a view or the rootView.
7227
3aaeb922a454 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7224
diff changeset
 14644
     If it's a view or rootView, it must be completely visible (or have
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14645
     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
 14646
     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
 14647
     and to read hardcopy images from the screen."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14648
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14649
    | visType
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14650
     x        "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14651
     y        "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14652
     w        "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14653
     h        "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14654
     dstIndex "{ Class: SmallInteger }"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14655
     srcIndex "{ Class: SmallInteger }"
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14656
     srcRow   "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14657
     dstRow   "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14658
     inData tmpData usedPixels mapSize
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14659
     map bytesPerLine
2534
35d91dcc4604 removed unused local
Claus Gittinger <cg@exept.de>
parents: 2533
diff changeset
 14660
     bitOrder spaceBitsPerPixel
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14661
     info bitsPerPixelIn bytesPerLineIn
3561
e2c3f84ff31f fixed pixmap readout for win32, where red and green are exchanged
Claus Gittinger <cg@exept.de>
parents: 3518
diff changeset
 14662
     bitsR "{ Class: SmallInteger }"
e2c3f84ff31f fixed pixmap readout for win32, where red and green are exchanged
Claus Gittinger <cg@exept.de>
parents: 3518
diff changeset
 14663
     bitsG "{ Class: SmallInteger }"
e2c3f84ff31f fixed pixmap readout for win32, where red and green are exchanged
Claus Gittinger <cg@exept.de>
parents: 3518
diff changeset
 14664
     bitsB "{ Class: SmallInteger }"
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14665
     maskR "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14666
     maskG "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14667
     maskB "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14668
     shR "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14669
     shG "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14670
     shB "{ Class: SmallInteger }"
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
 14671
     shR2 "{ Class: SmallInteger }"
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
 14672
     shG2 "{ Class: SmallInteger }"
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
 14673
     shB2 "{ Class: SmallInteger }"
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14674
     r "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14675
     g "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14676
     b "{ Class: SmallInteger }"
2019
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 14677
     word "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14678
     lword
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14679
     device ddepth isMSB bpp|
2019
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 14680
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 14681
    depth := self depth.
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14682
    bpp := "bitsPerPixel :=" self bitsPerPixel.
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14683
927
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 924
diff changeset
 14684
    device := aDrawable graphicsDevice.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14685
7637
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 14686
    aDrawable isForm ifTrue:[
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 14687
        aDrawable depth == 1 ifTrue:[
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 14688
            "/ a monochrome bitmap ?
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 14689
            visType := #StaticGray.
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 14690
            ddepth := 1.
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 14691
        ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14692
            visType := aDrawable photometric.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14693
            ddepth := aDrawable depth.
7637
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 14694
        ]. 
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14695
        photometric := aDrawable photometric.
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 14696
        samplesPerPixel := ddepth == 24 ifTrue:[3] ifFalse:[1].
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 14697
        bitsPerSample := ddepth == 24 ifTrue:[#[8 8 8]] ifFalse:[ByteArray with:bpp].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14698
    ] ifFalse:[
7637
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 14699
        "get some attributes of the display device"
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 14700
        visType := device visualType.
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 14701
        ddepth := device depth.
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 14702
        "/ kludge for 15bit XFree server
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 14703
        ddepth == 15 ifTrue:[
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 14704
            ddepth := 16
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 14705
        ].
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14706
        (visType == #StaticGray) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14707
            (device blackpixel == 0) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14708
                photometric := #blackIs0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14709
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14710
                photometric := #whiteIs0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14711
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14712
            samplesPerPixel := 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14713
            bpp := "bitsPerPixel :=" ddepth.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14714
            bitsPerSample := ByteArray with:bpp.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14715
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14716
            ((visType == #PseudoColor) or:[(visType == #StaticColor) or:[visType == #GrayScale]]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14717
                photometric := #palette.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14718
                samplesPerPixel := 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14719
                bpp := "bitsPerPixel :=" ddepth.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14720
                bitsPerSample := ByteArray with:bpp.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14721
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14722
                ((visType == #TrueColor) or:[visType == #DirectColor]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14723
                    photometric := #rgb.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14724
                    samplesPerPixel := 3.
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14725
    "/                bpp := "bitsPerPixel :=" depth.
4421
bcc5886c989c form -> image conversion fixes
james
parents: 4420
diff changeset
 14726
    "/                bitsPerSample := ByteArray with:device bitsRed
bcc5886c989c form -> image conversion fixes
james
parents: 4420
diff changeset
 14727
    "/                                       with:device bitsGreen
bcc5886c989c form -> image conversion fixes
james
parents: 4420
diff changeset
 14728
    "/                                       with:device bitsBlue
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14729
                    bpp := "bitsPerPixel :=" 24.
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 14730
                    bitsPerSample := #[8 8 8].
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14731
                ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14732
                    self error:'screen visual not supported'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14733
                    ^ nil
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14734
                ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14735
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14736
        ].
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14737
    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14738
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14739
    "
7227
3aaeb922a454 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7224
diff changeset
 14740
     don't know yet, how the display pads; assume worst case,
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14741
     offering enough space for 32 bit padding
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14742
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14743
    w := width := aRectangle width.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14744
    h := height := aRectangle height.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14745
    x := aRectangle left.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14746
    y := aRectangle top.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14747
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14748
    "
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14749
     a kludge: we don't know in advance how much we are going to need
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14750
     (its too late when info is present ...)
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14751
    "
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14752
    spaceBitsPerPixel := bpp.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14753
    (bpp > 8) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14754
        spaceBitsPerPixel := 16.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14755
        (bpp > 16) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14756
            spaceBitsPerPixel := 32.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14757
            (bpp > 32) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14758
                spaceBitsPerPixel := bpp.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14759
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14760
        ]
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14761
    ].
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14762
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14763
    bytesPerLine := (w * spaceBitsPerPixel + 31) // 32 * 4.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14764
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14765
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14766
     get the pixels
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14767
    "
1459
84e80b355553 splitted getBitsFrom into getBitsFromPixmap
Claus Gittinger <cg@exept.de>
parents: 1446
diff changeset
 14768
    aDrawable isForm ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14769
        (aDrawable id isNil and:[aDrawable bits notNil]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14770
            info := Dictionary new
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14771
                        at:#bitsPerPixel put:(aDrawable depth);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14772
                        at:#byteOrder put:#msbFirst;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14773
                        at:#bitOrder put:#msbFirst;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14774
                        at:#bytesPerLine put:(aDrawable width * aDrawable depth + 7)//8;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14775
                        yourself.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14776
            inData := aDrawable bits.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14777
        ] ifFalse:[
7637
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 14778
            inData := ByteArray new:(bytesPerLine * height).
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14779
            info := device getBitsFromPixmapId:aDrawable id x:x y:y width:w height:h into:inData.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14780
        ]
1459
84e80b355553 splitted getBitsFrom into getBitsFromPixmap
Claus Gittinger <cg@exept.de>
parents: 1446
diff changeset
 14781
    ] ifFalse:[
7637
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 14782
        inData := ByteArray new:(bytesPerLine * height).
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14783
        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
 14784
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14785
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14786
    bitsPerPixelIn := info at:#bitsPerPixel.
2533
3af95252b1b3 oops - ISMSB was not assigned
Claus Gittinger <cg@exept.de>
parents: 2532
diff changeset
 14787
7637
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 14788
    isMSB := (info at:#byteOrder) == #msbFirst.
2533
3af95252b1b3 oops - ISMSB was not assigned
Claus Gittinger <cg@exept.de>
parents: 2532
diff changeset
 14789
2029
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 14790
    "/
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 14791
    "/ check if bitorder is what I like (msbFirst)
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 14792
    "/
7206
Claus Gittinger <cg@exept.de>
parents: 7191
diff changeset
 14793
    "/ mhmh - that's not needed
2029
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 14794
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 14795
    bitsPerPixelIn < 8 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14796
        bitOrder := info at:#bitOrder.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14797
        bitOrder ~~ #msbFirst ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14798
            inData
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14799
                expandPixels:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14800
                width:(inData size)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14801
                height:1
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14802
                into:inData
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14803
                mapping:(ImageReader reverseBits "TODO: reverseBitsForDepth:bitsPerPixelIn").
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14804
        ].
2029
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 14805
    ].
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 14806
396
d088e672be8a handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents: 394
diff changeset
 14807
    "
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14808
     check, if the devices padding is different ..
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14809
     or if the bitsPerPixels are different
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14810
    "
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14811
    bytesPerLineIn := (info at:#bytesPerLine).           "what I got"
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14812
    bytesPerLine := (w * bpp + 7) // 8.                  "what I want"
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14813
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 14814
    maskR := info at:#redMask ifAbsent:[0].
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 14815
    maskG := info at:#greenMask ifAbsent:[0].
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 14816
    maskB := info at:#blueMask ifAbsent:[0].
3561
e2c3f84ff31f fixed pixmap readout for win32, where red and green are exchanged
Claus Gittinger <cg@exept.de>
parents: 3518
diff changeset
 14817
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14818
    ((bytesPerLine ~~ bytesPerLineIn)
7637
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 14819
     or:[bitsPerPixelIn ~~ bpp]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14820
        tmpData := inData.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14821
        inData := ByteArray uninitializedNew:(bytesPerLine * height).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14822
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14823
        srcRow := 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14824
        dstRow := 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14825
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14826
        bitsPerPixelIn ~~ bpp ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14827
            "/ for now, only 32 -> 24 is supported
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14828
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14829
            maskR == 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14830
                bitsR := device bitsRed.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14831
                bitsG := device bitsGreen.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14832
                bitsB := device bitsBlue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14833
                maskR := (1 bitShift:bitsR) - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14834
                maskG := (1 bitShift:bitsG) - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14835
                maskB := (1 bitShift:bitsB) - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14836
                shR := device shiftRed negated.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14837
                shG := device shiftGreen negated.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14838
                shB := device shiftBlue negated.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14839
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14840
                shR := (maskR lowBit - 1) negated.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14841
                bitsR := maskR highBit - maskR lowBit + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14842
                maskR := maskR bitShift:shR.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14843
                shG := (maskG lowBit - 1) negated.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14844
                bitsG := maskG highBit - maskG lowBit + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14845
                maskG := maskG bitShift:shG.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14846
                shB := (maskB lowBit - 1) negated.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14847
                bitsB := maskB highBit - maskB lowBit + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14848
                maskB := maskB bitShift:shB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14849
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14850
            shR2 := (8 - bitsR).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14851
            shG2 := (8 - bitsG).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14852
            shB2 := (8 - bitsB).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14853
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14854
            ((bitsPerPixelIn == 32) and:[bpp == 24]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14855
                "/ 'reformatting 32->24...' printNL.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14856
                1 to:h do:[:hi |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14857
                    srcIndex := srcRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14858
                    dstIndex := dstRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14859
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14860
                    1 to:w do:[:wi |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14861
                        lword := tmpData unsignedInt32At:srcIndex MSB:isMSB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14862
                        r := (lword bitShift:shR) bitAnd:maskR.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14863
                        g := (lword bitShift:shG) bitAnd:maskG.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14864
                        b := (lword bitShift:shB) bitAnd:maskB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14865
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14866
                        inData at:dstIndex   put:r.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14867
                        inData at:dstIndex+1 put:g.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14868
                        inData at:dstIndex+2 put:b.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14869
                        srcIndex := srcIndex + 4.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14870
                        dstIndex := dstIndex + 3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14871
                    ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14872
                    dstRow := dstRow + bytesPerLine.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14873
                    srcRow := srcRow + bytesPerLineIn
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14874
                ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14875
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14876
                ((bitsPerPixelIn == 16) and:[bpp == 24]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14877
                    "/ 'reformatting 16->24...' printNL.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14878
                    1 to:h do:[:hi |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14879
                        srcIndex := srcRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14880
                        dstIndex := dstRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14881
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14882
                        1 to:w do:[:wi |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14883
                            word := tmpData unsignedInt16At:srcIndex MSB:isMSB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14884
                            r := (word bitShift:shR) bitAnd:maskR.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14885
                            g := (word bitShift:shG) bitAnd:maskG.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14886
                            b := (word bitShift:shB) bitAnd:maskB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14887
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14888
                            inData at:dstIndex   put:(r bitShift:shR2).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14889
                            inData at:dstIndex+1 put:(g bitShift:shG2).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14890
                            inData at:dstIndex+2 put:(b bitShift:shB2).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14891
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14892
                            srcIndex := srcIndex + 2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14893
                            dstIndex := dstIndex + 3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14894
                        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14895
                        dstRow := dstRow + bytesPerLine.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14896
                        srcRow := srcRow + bytesPerLineIn
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14897
                    ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14898
                ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14899
                    ('Image [warning]: unsupported depth combination: ' , bitsPerPixelIn printString , ' -> ' ,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14900
                                                        bpp printString) errorPrintCR.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14901
                    self shouldImplement.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14902
                    ^ nil
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14903
                ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14904
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14905
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14906
            "/
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14907
            "/ repad in the buffer
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14908
            "/
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14909
            1 to:h do:[:hi |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14910
                inData replaceFrom:dstRow to:(dstRow + bytesPerLine - 1)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14911
                              with:tmpData startingAt:srcRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14912
                dstRow := dstRow + bytesPerLine.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14913
                srcRow := srcRow + bytesPerLineIn
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14914
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14915
        ]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14916
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14917
        (bytesPerLine * height) ~~ inData size ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14918
            tmpData := inData.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14919
            inData := ByteArray uninitializedNew:(bytesPerLine * height).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14920
            inData replaceFrom:1 to:bytesPerLine * height with:tmpData startingAt:1
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14921
        ]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14922
    ].
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 14923
    self bits:inData.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14924
3864
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
 14925
    "/
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
 14926
    "/  if not #palette we are done, the pixel values are the rgb/grey values
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
 14927
    "/
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
 14928
    photometric == #palette ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14929
        "/
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14930
        "/ what we now have are the color numbers - still need the r/g/b values.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14931
        "/ find out, which colors are in the picture
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14932
        "/
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14933
        usedPixels := inData usedValues.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14934
        mapSize := usedPixels max + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14935
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14936
        "get the palette"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14937
        map := Array new:mapSize.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14938
        usedPixels do:[:colorIndex |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14939
            |i|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14940
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14941
            i := colorIndex + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14942
            device
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14943
                getRGBFrom:colorIndex
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14944
                into:[:r :g :b |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14945
                    map at:i put:(Color red:r green:g blue:b)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14946
                ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14947
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14948
        self setColorMap:map.
1644
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 14949
    ].
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 14950
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 14951
    "Modified: / 07-02-1998 / 18:23:07 / cg"
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 14952
    "Modified: / 31-01-2017 / 15:02:52 / stefan"
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14953
!
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14954
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14955
fromScreen:aRectangle
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 14956
    "read an image from the display screen.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 14957
     WARNING: this temporarily grabs the display
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14958
              it may not work from within a buttonMotion
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14959
              (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
 14960
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14961
    ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14962
        fromScreen:aRectangle
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14963
        on:Screen current
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14964
        grab:true
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14965
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 14966
    "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
 14967
!
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14968
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14969
fromScreen:aRectangle on:aDevice
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14970
    "read an image from aDevices display screen.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14971
     Since I have no other displays, only the MonoChrome, StaticGrey
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14972
     and PseudoColor cases have been tested ...
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14973
     (especially True- and DirectColor may be wrong).
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 14974
     Late note: 24bit rgb now also works.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 14975
     WARNING: this temporarily grabs the display
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14976
              it may not work from within a buttonMotion
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14977
              (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
 14978
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14979
    ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14980
        fromScreen:aRectangle
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14981
        on:aDevice
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14982
        grab:true
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 14983
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 14984
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 14985
     Image fromScreen:((0 @ 0) corner:(100 @ 100)) on:Display
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 14986
     Image fromScreen:((0 @ 0) corner:(500 @ 500)) on:Display
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 14987
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 14988
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 14989
    "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
 14990
!
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14991
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14992
fromScreen:aRectangle on:aDevice grab:doGrab
7227
3aaeb922a454 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7224
diff changeset
 14993
    "read an image from aDevice's display screen.
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14994
     If the doGrab argument is true, the display
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14995
     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
 14996
     shown while the readout is done.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14997
     Since I have no other displays, only the MonoChrome, StaticGrey
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14998
     and PseudoColor cases have been tested ...
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14999
     (especially True- and DirectColor may be wrong).
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 15000
     Late note: 24bit rgb now also works.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 15001
     WARNING: with doGrab true, this temporarily grabs the display
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15002
              and it may not work from within a buttonMotion
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15003
              (use with a false grabArg then)."
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 15004
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 15005
    |curs rootView prevGrab|
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 15006
6613
3b0f0fb40c2c class: Image
Claus Gittinger <cg@exept.de>
parents: 6592
diff changeset
 15007
    curs := nil.
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 15008
"/    doGrab ifTrue:[ |cid|
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 15009
"/        curs := Cursor sourceForm:(Image fromFile:'bitmaps/Camera.xbm')
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 15010
"/                         maskForm:(Image fromFile:'bitmaps/Camera_m.xbm')
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 15011
"/                          hotSpot:16@16.
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 15012
"/        curs notNil ifTrue:[
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 15013
"/            cid := (curs onDevice:aDevice) id
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 15014
"/        ].
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 15015
"/    ].
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 15016
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 15017
    "
7227
3aaeb922a454 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7224
diff changeset
 15018
     actually have to grabServer ... but that's not yet available
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 15019
    "
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 15020
    rootView := aDevice rootView.
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 15021
    doGrab ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15022
        prevGrab := aDevice activePointerGrab.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15023
        aDevice grabPointerInView:rootView withCursor:curs.
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 15024
    ].
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 15025
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 15026
    "
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 15027
     get the pixels
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 15028
    "
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 15029
    [
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15030
        self from:rootView in:aRectangle.
3605
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
 15031
    ] ensure:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15032
        doGrab ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15033
            aDevice ungrabPointer.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15034
            prevGrab notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15035
                 aDevice grabPointerInView:prevGrab.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15036
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15037
        ]
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 15038
    ]
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 15039
3092
0f1a9ec64574 restore grab after #imageFromUser
ca
parents: 3059
diff changeset
 15040
    "
0f1a9ec64574 restore grab after #imageFromUser
ca
parents: 3059
diff changeset
 15041
     Image fromScreen:((100@100) corner:(200@200)) on:Display grab:false
0f1a9ec64574 restore grab after #imageFromUser
ca
parents: 3059
diff changeset
 15042
     Image fromScreen:((100@100) corner:(200@200)) on:Display grab:true
0f1a9ec64574 restore grab after #imageFromUser
ca
parents: 3059
diff changeset
 15043
    "
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15044
!
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15045
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15046
photometricFromScreen:aDevice
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15047
    "read aDevices display photometric and set my colormap for it.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15048
     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
 15049
     or from an offScreen bitmap, for correct pixel interpretation."
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15050
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15051
    |depth visType bitsPerPixel|
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15052
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15053
    "
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15054
     get some attributes of the display device
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15055
    "
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15056
    visType := aDevice visualType.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15057
    depth := aDevice depth.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15058
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15059
    "/ kludge for 15bit XFree server
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15060
    depth == 15 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15061
        depth := 16
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15062
    ].
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15063
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15064
    (visType == #StaticGray) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15065
        (aDevice blackpixel == 0) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15066
            photometric := #blackIs0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15067
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15068
            photometric := #whiteIs0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15069
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15070
        samplesPerPixel := 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15071
        bitsPerPixel := depth.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15072
        bitsPerSample := ByteArray with:bitsPerPixel.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15073
        "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15074
         were done, the pixel values are the grey values
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15075
        "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15076
        ^ self
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15077
    ].
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15078
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15079
    ((visType == #TrueColor) or:[visType == #DirectColor]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15080
        photometric := #rgb.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15081
        samplesPerPixel := 3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15082
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15083
        "/ for now - only support 24bit TrueColor
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15084
        depth ~~ 24 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15085
            'IMAGE: unsupported display depth' errorPrintCR.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15086
        ].
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15087
"/                bitsPerPixel := depth.
4115
0e783379a6b0 Use ByteArray for bitsPerSample (255 should be enough ;-)
Stefan Vogel <sv@exept.de>
parents: 4109
diff changeset
 15088
"/                bitsPerSample := ByteArray with:aDevice bitsRed
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15089
"/                                       with:aDevice bitsGreen
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15090
"/                                       with:aDevice bitsBlue
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15091
        bitsPerPixel := 24.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15092
        bitsPerSample := #[8 8 8].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15093
        "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15094
         were done, the pixel values are the rgb values
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15095
        "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15096
        ^ self
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 15097
    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 15098
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 15099
    ((visType ~~ #PseudoColor)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 15100
    and:[(visType ~~ #StaticColor)
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15101
    and:[visType ~~ #GrayScale]]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15102
        self error:'screen visual not supported'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 15103
        ^ nil
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15104
    ].
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15105
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15106
    photometric := #palette.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15107
    samplesPerPixel := 1.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15108
    bitsPerPixel := depth.
4115
0e783379a6b0 Use ByteArray for bitsPerSample (255 should be enough ;-)
Stefan Vogel <sv@exept.de>
parents: 4109
diff changeset
 15109
    bitsPerSample := ByteArray with:bitsPerPixel.
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15110
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15111
    "
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15112
     still need the pixels r/g/b values ...
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15113
    "
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
 15114
    self setColorMap:aDevice colorMap
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15115
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15116
    "Modified: 11.7.1996 / 11:11:34 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 15117
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 15118
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15119
!Image methodsFor:'virtual anti-aliased'!
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15120
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
 15121
vitualAntiAliasedAlongXvertical:bottomOrTop horizontal:leftOrRight form:tempForm color:aColor xRun:xRun yRun:yRun colorDictionary:colorDictionary blendStart:blendStart
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15122
    |isBottom isLeft additionalY workPoint startX endX pixels pixelPos percent distance nearestKey tmp|
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15123
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15124
    isBottom := bottomOrTop sameAs:#bottom.
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15125
    isBottom ifTrue:[
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15126
        additionalY := -1.
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15127
    ] ifFalse:[
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15128
        additionalY := 1.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15129
    ].
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15130
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15131
    isLeft := leftOrRight sameAs:#left.
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15132
    isLeft ifTrue:[
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15133
        workPoint := (xRun - 1)@yRun.
7640
25640118d11f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7637
diff changeset
 15134
        [
25640118d11f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7637
diff changeset
 15135
            ((tempForm pixelAtX:workPoint x y:workPoint y) == 0)
25640118d11f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7637
diff changeset
 15136
            and:[ ((tempForm pixelAtX:workPoint x y:workPoint y + additionalY) == 1) 
25640118d11f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7637
diff changeset
 15137
            and:[ ((tempForm pixelAtX:workPoint x - 1 y:workPoint y + additionalY) == 1) ]]
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15138
        ] whileTrue:[
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15139
            startX := workPoint x.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15140
            endX isNil ifTrue:[endX := workPoint x].
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15141
            workPoint := (workPoint x - 1)@yRun.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15142
        ].
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15143
    ] ifFalse:[
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15144
        workPoint := (xRun + 1)@yRun.
7640
25640118d11f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7637
diff changeset
 15145
        [
25640118d11f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7637
diff changeset
 15146
            ((tempForm pixelAtX:workPoint x y:workPoint y) == 0)
25640118d11f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7637
diff changeset
 15147
            and:[ ((tempForm pixelAtX:workPoint x y:workPoint y + additionalY) == 1) 
25640118d11f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7637
diff changeset
 15148
            and:[ ((tempForm pixelAtX:workPoint x + 1 y:workPoint y + additionalY) == 1) ]]
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15149
        ] whileTrue:[
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15150
            endX := workPoint x.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15151
            startX isNil ifTrue:[startX := workPoint x].
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15152
            workPoint := (workPoint x + 1)@yRun.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15153
        ].
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15154
    ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15155
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15156
    (startX notNil and:[endX notNil]) ifTrue:[
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15157
        startX = endX ifTrue:[
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15158
            self atImageAndMask:startX@yRun putValue:((colorDictionary at:aColor) at:blendStart).
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15159
        ] ifFalse:[
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15160
            pixels := (endX - startX) + 1.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15161
            startX to:endX do:[:x |
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15162
                isLeft ifTrue:[
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15163
                    pixelPos := (x - startX) + 1.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15164
                ] ifFalse:[
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15165
                    pixelPos := (endX - x) + 1.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15166
                ].
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15167
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15168
                percent := (100 / (pixels / pixelPos)) asFloat / 100.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15169
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15170
                (colorDictionary at:aColor) keys do:[:aKey |
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15171
                    nearestKey isNil ifTrue:[
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15172
                        distance := percent dist:aKey.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15173
                        nearestKey := aKey.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15174
                    ] ifFalse:[
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15175
                        tmp := percent dist:aKey.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15176
                        distance > tmp ifTrue:[
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15177
                            distance := tmp.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15178
                            nearestKey := aKey.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15179
                        ].
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15180
                    ].
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15181
                ].
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15182
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15183
                self atImageAndMask:x@yRun putValue:((colorDictionary at:aColor) at:nearestKey).
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15184
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15185
                distance := nil.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15186
                nearestKey := nil.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15187
            ].
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15188
        ].
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15189
    ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15190
!
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15191
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
 15192
vitualAntiAliasedAlongYhorizontal:leftOrRight vertical:bottomOrTop form:tempForm color:aColor xRun:xRun yRun:yRun colorDictionary:colorDictionary blendStart:blendStart
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15193
    |isLeft isBottom additionalX workPoint startY endY pixels pixelPos percent distance nearestKey tmp|
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15194
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15195
    isLeft := leftOrRight sameAs:#left.
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15196
    isLeft ifTrue:[
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15197
        additionalX := 1.
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15198
    ] ifFalse:[
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15199
        additionalX := -1.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15200
    ].
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15201
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15202
    isBottom := bottomOrTop sameAs:#bottom.
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15203
    isBottom ifTrue:[
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15204
        workPoint := xRun@(yRun + 1).
7640
25640118d11f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7637
diff changeset
 15205
        [
25640118d11f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7637
diff changeset
 15206
            ((tempForm pixelAtX:workPoint x y:workPoint y) == 0) 
25640118d11f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7637
diff changeset
 15207
            and:[ ((tempForm pixelAtX:workPoint x + additionalX y:workPoint y) == 1) 
25640118d11f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7637
diff changeset
 15208
            and:[ ((tempForm pixelAtX:workPoint x + additionalX y:workPoint y + 1) == 1) ]]
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15209
        ] whileTrue:[
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15210
            endY := workPoint y.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15211
            startY isNil ifTrue:[startY := workPoint y].
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15212
            workPoint := xRun@(workPoint y + 1).
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15213
        ].
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15214
    ] ifFalse:[
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15215
        workPoint := xRun@(yRun - 1).
7640
25640118d11f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7637
diff changeset
 15216
        [
25640118d11f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7637
diff changeset
 15217
            ((tempForm pixelAtX:workPoint x y:workPoint y) == 0) 
25640118d11f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7637
diff changeset
 15218
            and:[ ((tempForm pixelAtX:workPoint x + additionalX y:workPoint y) == 1) 
25640118d11f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7637
diff changeset
 15219
            and:[ ((tempForm pixelAtX:workPoint x + additionalX y:workPoint y - 1) == 1) ]]
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15220
        ] whileTrue:[
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15221
            startY := workPoint y.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15222
            endY isNil ifTrue:[endY := workPoint y].
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15223
            workPoint := xRun@(workPoint y - 1).
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15224
        ].
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15225
    ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15226
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15227
    (startY notNil and:[endY notNil]) ifTrue:[
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15228
        startY = endY ifTrue:[
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15229
            self atImageAndMask:xRun@startY putValue:((colorDictionary at:aColor) at:blendStart).
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15230
        ] ifFalse:[
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15231
            pixels := (endY - startY) + 1.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15232
            startY to:endY do:[:y |
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15233
                isBottom ifTrue:[
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15234
                    pixelPos := (endY - y) + 1.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15235
                ] ifFalse:[
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15236
                    pixelPos := (y - startY) + 1.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15237
                ].
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15238
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15239
                percent := (100 / (pixels / pixelPos)) asFloat / 100.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15240
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15241
                (colorDictionary at:aColor) keys do:[:aKey |
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15242
                    nearestKey isNil ifTrue:[
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15243
                        distance := percent dist:aKey.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15244
                        nearestKey := aKey.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15245
                    ] ifFalse:[
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15246
                        tmp := percent dist:aKey.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15247
                        distance > tmp ifTrue:[
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15248
                            distance := tmp.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15249
                            nearestKey := aKey.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15250
                        ].
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15251
                    ].
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15252
                ].
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15253
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15254
                self atImageAndMask:xRun@y putValue:((colorDictionary at:aColor) at:nearestKey).
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15255
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15256
                distance := nil.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15257
                nearestKey := nil.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15258
            ].
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15259
        ].
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15260
    ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15261
! !
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15262
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
 15263
!Image class methodsFor:'documentation'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 15264
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 15265
version
6894
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
 15266
    ^ '$Header$'
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
 15267
!
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
 15268
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
 15269
version_CVS
6894
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
 15270
    ^ '$Header$'
6912
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
 15271
!
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
 15272
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
 15273
version_HG
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
 15274
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
 15275
    ^ '$Changeset: <not expanded> $'
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
 15276
! !
3759
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
 15277
6037
eea2343b0b1e Refactoring:
Stefan Vogel <sv@exept.de>
parents: 5956
diff changeset
 15278
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 15279
Image initialize!