Image.st
author Claus Gittinger <cg@exept.de>
Fri, 03 Feb 2017 16:57:28 +0100
changeset 7834 329ce8391689
parent 7824 1ecfb677d8d7
child 7840 dedc215d1631
permissions -rw-r--r--
#BUGFIX by cg class: Image changed: #colorMap: #setColorMap: #storeOn: care for FixedPalette
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'
7834
329ce8391689 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7824
diff changeset
    21
	classVariableNames:'BadImageFormatQuerySignal CannotRepresentImageSignal
329ce8391689 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7824
diff changeset
    22
		CollectGarbageWhenRunningOutOfColors DitherAlgorithm
329ce8391689 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7824
diff changeset
    23
		FileCreationErrorSignal ImageErrorSignal ImageLoadErrorSignal
329ce8391689 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7824
diff changeset
    24
		ImageNotFoundQuerySignal ImageSaveErrorSignal
329ce8391689 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7824
diff changeset
    25
		InformationLostQuerySignal Lobby NumberOfDitherColors
7529
5f77a718b7bd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7523
diff changeset
    26
		UnrepresentableColorSignal'
5f77a718b7bd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7523
diff changeset
    27
	poolDictionaries:''
5f77a718b7bd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7523
diff changeset
    28
	category:'Graphics-Images'
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    29
!
48194c26a46c Initial revision
claus
parents:
diff changeset
    30
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
    31
!Image class methodsFor:'documentation'!
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    32
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    33
copyright
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    34
"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    35
 COPYRIGHT (c) 1991 by Claus Gittinger
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
    36
              All Rights Reserved
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    37
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    38
 This software is furnished under a license and may be used
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    39
 only in accordance with the terms of that license and with the
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    40
 inclusion of the above copyright notice.   This software may not
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    41
 be provided or otherwise made available to, or used by, any
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    42
 other person.  No title to or ownership of the software is
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    43
 hereby transferred.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    44
"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    45
!
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    46
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    47
documentation
48194c26a46c Initial revision
claus
parents:
diff changeset
    48
"
6284
ebd0dfb1322c cleanup - removed unused instvars
Claus Gittinger <cg@exept.de>
parents: 6256
diff changeset
    49
    this class provides representation for all kinds of images
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
    50
    (monochrome, greyscale and color) and may finally replace Form.
6166
87e576aea243 class: Image
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
    51
    Depths of 1, 2, 4, 8, 16, 24 and 32 are supported.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    52
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    53
    An Image keeps all of its information in a device independent way,
6166
87e576aea243 class: Image
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
    54
    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
    55
    The data held keeps all information which was originally present,
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    56
    even if the display-device has lower resolution.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    57
    Therefore, it is possible to process and manipulate images without loosing
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    58
    color information.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    59
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    60
    Images may be created manually (by providing a pixel array),
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
    61
    by screen capture, by reading a file (using an ImageReader) or
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
    62
    dynamically computed by a pixelFunction (functional image).
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
    63
6166
87e576aea243 class: Image
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
    64
    This gives you a device independent image.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    65
    For display, a device representation is required, which can be
7404
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
    66
    acquired by sending the 'onDevice:aDevice' message to the image.
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
    67
    This creates a (possibly dithered) device-form,
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    68
    representing the image using the currently available colors.
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    69
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    70
    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
    71
    (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
    72
    it the message
7404
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
    73
        'monochromeOn:aDevice'.
6284
ebd0dfb1322c cleanup - removed unused instvars
Claus Gittinger <cg@exept.de>
parents: 6256
diff changeset
    74
ebd0dfb1322c cleanup - removed unused instvars
Claus Gittinger <cg@exept.de>
parents: 6256
diff changeset
    75
    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
    76
    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
    77
    with color allocation optimizations and dithering. Nowadays, these are hardly ever needed,
87e576aea243 class: Image
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
    78
    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
    79
    to a device representation.
286
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    80
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    81
    An images pixel interpretation is controlled by the photometric instance variable
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    82
    and (if that is #palette) a colorMap.
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    83
    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
    84
    (and using specialized colorMaps for b&w / greyScale images).
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    85
    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
    86
286
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    87
    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
    88
    which have the file-format knowledge built in.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    89
    There are readers for most common formats available
286
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    90
    (see ImageReader and especially subclasses such as TIFFReader, GIFReader etc.).
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    91
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    92
    File formats are handled by subclasses of ImageReader, which understand
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    93
    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
    94
    to the mapping maintained in the MIMETypes class.
87e576aea243 class: Image
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
    95
    (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
    96
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    97
    Some algorithms used here (especially dithering & color allocation) are
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    98
    experimental and far from being perfect (some are very slow).
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    99
    For now, the most common cases have been optimized and perform reasonably
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   100
    fast - however, with uncommon depth/visualType combinations, you may
6166
87e576aea243 class: Image
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
   101
    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
   102
    write a specially tuned (inline-C) version for that case.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   103
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   104
    The pixelFunction enables dynamically computed functional images: instead of
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   105
    providing a byteArray containing pixel data, a function is used which maps
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   106
    x/y coordinates to a pixel value (see examples).
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   107
    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
   108
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   109
    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
   110
    (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
   111
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   112
    Dithering can be controlled by the DitherAlgorithm classVariable:
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
   113
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   114
       DitherAlgorithm:
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   115
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   116
       nil                  a simple threshold algorithm
7404
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   117
                            (i.e. for mono, p<0.5 -> black, p>=0.5 -> white)
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   118
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   119
       #pattern             patterned dither
7404
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   120
                            (for p, take dithered color to fill pixel;
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   121
                             uses dithering in color-class)
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   122
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   123
       #error               error diffusion dither (Floyd-Steinberg)
7404
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   124
                            planned - not yet implemented.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   125
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   126
6862
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
   127
    Notice:
7404
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   128
        the set of attributes and the way they are stored originated initially
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   129
        from the need to represent tiff images. These turned out to use a relatively
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   130
        large set of atributes, of which many are unused in other image formats.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   131
        (so it was sufficient).
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   132
        Later, some VisualWorks compatibility protocol was added (mapped palettes, for
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   133
        example), and some stuff could well be redefined in simpler ways.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   134
        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
   135
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   136
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   137
    [instance variables:]
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   138
7404
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   139
        width               <Integer>       the width in pixels
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   140
        height              <Integer>       the height in pixels
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   141
        bytes               <ByteArray>     the full image information
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   142
        photometric         <Symbol>        #rgb, #palette, #blackIs0 or #whiteIs0
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   143
        samplesPerPixel     <Integer>       the number of planes
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   144
        bitsPerSample       <Array>         the number of bits per plane
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   145
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   146
        colorMap            <Array>         only if photometric is #palette;
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   147
                                            maps pixel values to r/g/b values.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   148
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   149
        device              <Workstation>   the device on which deviceForm,
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   150
                                            monoDeviceForm and lowResDeviceForm are
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   151
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   152
        deviceForm          <Form>          the device form which gives the best
7621
e6755d298330 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7596
diff changeset
   153
                                            possible approximation of the image on
7404
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   154
                                            device using standard colors.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   155
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   156
        monoDeviceForm      <Form>          the device form which gives a monochrome
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   157
                                            aproximation of the image on device.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   158
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   159
        fullColorDeviceForm <Form>          the device form which gives the best
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   160
                                            possible aproximation of the image on
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   161
                                            device using private colors.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   162
                                            (not yet implemented)
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   163
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   164
        mask                <ImageMask>     an optional mask;
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   165
                                            if non-nil, only pixels for which the
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   166
                                            corresponding mask bit is non-zero
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   167
                                            are drawn.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   168
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   169
        maskedPixelsAre0    <Boolean>       a hint for image processors and drawers
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   170
                                            if true, masked pixels are known to be
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   171
                                            zero in the pixel bytes.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   172
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   173
        fileName            <String>        the name of the file from which the
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   174
                                            image was loaded - nil otherwise.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   175
                                            Useful for image save functions
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   176
                                            and for the UIPainter utility.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   177
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   178
        imageSequence                       the imageSequence, of which the
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   179
                                            instance is a frame or nil,
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   180
                                            if its not part of a sequence.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   181
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   182
        bitsPerPixel                        obsolete - not used in ST/X (kept for a while for subclasses)
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   183
        depth                               - these have been added in instVar-slots
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   184
        maxPixelValue                       - according to the ST-80's image class.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   185
        rowByteSize                         - to allow loading of st-80 images
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   186
                                            - (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
   187
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   188
    [class variables:]
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   189
7404
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   190
        Lobby               <Registry>      keeps track of known images
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   191
                                            (for resource freeing with garbage collector)
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   192
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   193
        DitherAlgorithm     <Symbol>        defines how to dither
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   194
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   195
        NumberOfDitherColors <Integer>      defines, how many dither colors to use
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   196
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   197
        FileFormats         <Dictionary>    associates filename extensions to
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   198
                                            image reader classes (now set-up in startup-file)
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   199
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   200
        CollectGarbageWhenRunningOutOfColors
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   201
                            <Boolean>       if true, and we run out of available
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   202
                                            device colors during creation of a
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   203
                                            device image, collect garbage for
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   204
                                            possible image reclamation.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   205
                                            If false, proceed immediately.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   206
                                            Default is true.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   207
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   208
        ImageNotFoundQuerySignal
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   209
                            <QuerySignal>   raised, if an image could not be loaded
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   210
                                            from a file. The parameter is the images
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   211
                                            fileName.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   212
                                            A handler may return a replacement
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   213
                                            image or proceed with nil.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   214
                                            If unhandled, a nil is returned from the
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   215
                                            image creation.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   216
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   217
        BadImageFormatQuerySignal
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   218
                            <QuerySignal>   raised, if an image could not be loaded
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   219
                                            from a file due to a file error or
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   220
                                            unsupported format.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   221
                                            A handler may return a replacement
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   222
                                            image or proceed with nil.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   223
                                            If unhandled, a nil is returned from the
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   224
                                            image creation.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   225
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   226
        ImageSaveErrorSignal
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   227
                            <Signal>        parent of errors below.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   228
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   229
        FileCreationErrorSignal
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   230
                            <Signal>        file could not be created when saving an
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   231
                                            image.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   232
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   233
        CannotRepresentImageSignal
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   234
                            <Signal>        the specified ImageReader cannot represent
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   235
                                            the given image.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   236
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   237
        InformationLostQuerySignal
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   238
                            <Signal>        the specified ImageReader can represent
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   239
                                            the given image, but some information
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   240
                                            (typically color resolution) is lost.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   241
                                            If unhandled, the save proceeds as usual.
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
   242
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
    caveat:
7404
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   245
        the information in
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   246
            photometric, bitsPerPixel, bitsPerSample, samplesPerPixel, depth , colorMap and maxPixelValue
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   247
        is partially redundant and its handling stupid (not to say: braindamaged ;-).
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   248
        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
   249
        compatibility reasons (mostly coming from tiff format, which was the very first supported format).
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   250
        All of the above belongs into the single colorMap which must migrate from
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   251
        a stupid seqColl to a color-aware real colorMap.
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   252
        (we are in the process of doing so...)
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
   253
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   254
    todo:
7404
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   255
        support alpha masks
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   256
        cleanup the dithering & conversion code
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   257
        cleanup the color/photometric mess
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   258
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   259
    [See also:]
7404
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   260
        Form Icon ImageReader
611
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   261
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   262
    [author:]
7404
e14e8afef2e4 #OTHER by mawalch
mawalch
parents: 7374
diff changeset
   263
        Claus Gittinger
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   264
"
649
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   265
!
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   266
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   267
examples
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   268
"
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   269
    reading from a file (many formats are supported):
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   270
    (notice that the bitmaps directory is searched for along
2645
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   271
     the system path - therefore, you may add your own bitmap
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   272
     directory to the beginning of the path and thus override
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   273
     any default bitmaps, or make certain that your application
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   274
     finds its bitmaps - even if they are in a separate directory)
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   275
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   276
                                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   277
        (Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif') inspect
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   278
                                                                                        [exEnd]
7523
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
   279
    Boy, was I young, when writing ST/X... ;-)                                                                                                 
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
   280
                                                                                        [exBegin]
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
   281
        (Image fromFile:'../../goodies/bitmaps/gifImages/claus.gif') inspect
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
   282
        ((Image fromFile:'../../goodies/bitmaps/gifImages/claus.gif') rotated:90) inspect
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
   283
        ((Image fromFile:'../../goodies/bitmaps/gifImages/claus.gif') rotated:45) inspect
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
   284
        ((Image fromFile:'../../goodies/bitmaps/gifImages/claus.gif') rotated:25) inspect
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
   285
                                                                                        [exEnd]
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
   286
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
   287
                                                                                        
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   288
    better use package relative file names:
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   289
                                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   290
        (Image fromFile:'bitmaps/gifImages/garfield.gif' inPackage:'stx:goodies') inspect
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   291
                                                                                        [exEnd]
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   292
    various file formats are supported:
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   293
                                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   294
        (Image fromFile:'bitmaps/xpmBitmaps/misc_icons/SmalltalkX_clr.xpm' inPackage:'stx:goodies') inspect
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   295
                                                                                        [exEnd]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   296
                                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   297
        (Image fromFile:'bitmaps/winBitmaps/okSmily_up.bmp' inPackage:'stx:goodies') inspect
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   298
                                                                                        [exEnd]
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   299
7222
matilk
parents: 7210
diff changeset
   300
    drawing
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   301
                                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   302
        |imageClass image|
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   303
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   304
        imageClass := Image implementorForDepth:24.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   305
        image      := imageClass width: 100 height: 50.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   306
        image bits:(ByteArray new:(image bytesPerRow*50)).
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   307
        image fillRectangle:(0@0 extent:100@50) withColor:Color yellow.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   308
        image drawRectangle:(10@10 extent:20@20) withColor:Color red.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   309
        image fillRectangle:(40@20 extent:20@20) withColor:Color green.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   310
                                                                                        [exEnd]
7222
matilk
parents: 7210
diff changeset
   311
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   312
    The following examples demonstrate various depth and colorMap variations ...
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   313
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   314
    inline image:
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   315
      default: depth=1 & #blackIs0
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   316
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   317
        (Image
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   318
            width:8 height:8
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   319
            fromArray:#( 2r11111111
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   320
                         2r10000001
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
                         2r11111111 )
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   327
        ) edit
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   328
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   329
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   330
      with #whiteIs0 photometric
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   331
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   332
        ((Image width:8 height:8
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   333
               fromArray:#( 2r11111111
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   334
                            2r10000001
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
                            2r11111111 ))
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   341
            photometric:#whiteIs0
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   342
        ) edit
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   343
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   344
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   345
      with a colorMap
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   346
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   347
        ((Image width:8 height:8
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   348
               fromArray:#( 2r11111111
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   349
                            2r10000001
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
                            2r11111111 ))
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   356
            colorMap:(Array with:(Color red)
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   357
                            with:(Color yellow))
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   358
        ) edit
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   359
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   360
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   361
      a depth4 greyScale image:
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   362
      (default photometric is #blackIs0)
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   363
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   364
        (Depth4Image
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   365
             width:8
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   366
             height:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   367
             fromArray:#[
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   368
                            16r00 16r11 16r22 16r33
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   369
                            16r44 16r55 16r66 16r77
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   370
                            16r88 16r99 16raa 16rbb
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   371
                            16rcc 16rdd 16ree 16rff
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   372
                        ]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   373
        ) edit
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   374
                                                                        [exEnd]
2645
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   375
      the same, magnified:
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   376
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   377
        ((Depth4Image
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   378
             width:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   379
             height:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   380
             fromArray:#[
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   381
                            16r01 16r23
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   382
                            16r45 16r67
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   383
                            16r89 16rab
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   384
                            16rcd 16ref
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   385
                        ])
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   386
            magnifiedBy:30
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   387
        ) edit
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   388
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   389
      the following has the same effect:
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   390
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   391
        ((Image
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   392
             width:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   393
             height:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   394
             depth:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   395
             fromArray:#[
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   396
                            16r01 16r23
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   397
                            16r45 16r67
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   398
                            16r89 16rab
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   399
                            16rcd 16ref
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   400
                        ])
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   401
            magnifiedBy:30
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   402
        ) edit
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   403
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   404
      with reverse grey-interpretation:
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   405
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   406
        ((Depth4Image
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   407
             width:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   408
             height:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   409
             fromArray:#[
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   410
                            16r01 16r23
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   411
                            16r45 16r67
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   412
                            16r89 16rab
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   413
                            16rcd 16ref
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   414
                        ])
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   415
            photometric:#whiteIs0;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   416
            magnifiedBy:30
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   417
        ) edit
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   418
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   419
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   420
      with 1-bit-per-pixel rgb interpretation:
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   421
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   422
        ((Depth4Image
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   423
             width:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   424
             height:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   425
             fromArray:#[
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   426
                            16r01 16r23
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   427
                            16r45 16r67
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   428
                            16r89 16rab
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   429
                            16rcd 16ref
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   430
                        ])
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   431
            photometric:#rgb;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   432
            samplesPerPixel:3;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   433
            bitsPerSample:#(1 1 1);
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   434
            magnifiedBy:30
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   435
        ) edit
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   436
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   437
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   438
      with 1/2/1 rgb interpretation:
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   439
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   440
        ((Depth4Image
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   441
             width:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   442
             height:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   443
             fromArray:#[
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   444
                            16r01 16r23
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   445
                            16r45 16r67
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   446
                            16r89 16rab
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   447
                            16rcd 16ref
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   448
                        ])
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   449
            photometric:#rgb;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   450
            samplesPerPixel:3;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   451
            bitsPerSample:#(1 2 1);
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   452
            magnifiedBy:30
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   453
        ) edit
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   454
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   455
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   456
      a 2/2/0 rgb image (i.e. no blue):
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   457
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   458
         |i|
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   459
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   460
         i := Depth4Image
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   461
                    width:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   462
                    height:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   463
                    fromArray:#[ 16r01 16r23
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   464
                                 16r45 16r67
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   465
                                 16r89 16rab
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   466
                                 16rcd 16ref ].
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   467
         i photometric:#rgb.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   468
         i samplesPerPixel:3.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   469
         i bitsPerSample:#(2 2 0).
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   470
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   471
         i := i magnifiedBy:30.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   472
         i edit.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   473
                                                                        [exEnd]
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   474
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   475
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   476
      a 0/0/4 rgb image (i.e. no red or green):
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   477
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   478
         |i|
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   479
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   480
         i := Depth4Image
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   481
                    width:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   482
                    height:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   483
                    fromArray:#[ 16r01 16r23
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   484
                                 16r45 16r67
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   485
                                 16r89 16rab
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   486
                                 16rcd 16ref ].
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   487
         i photometric:#rgb.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   488
         i samplesPerPixel:3.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   489
         i bitsPerSample:#(0 0 4).
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   490
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   491
         i := i magnifiedBy:30.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   492
         i edit.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   493
                                                                        [exEnd]
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   494
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   495
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   496
      a 2plane greyscale image:
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   497
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   498
        ((Depth2Image
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   499
             width:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   500
             height:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   501
             fromArray:#[
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   502
                            4r0123
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   503
                            4r1230
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   504
                            4r2301
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   505
                            4r3012
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   506
                        ])
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   507
            magnifiedBy:30
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   508
        ) edit
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   509
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   510
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   511
      with colors:
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   512
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   513
        ((Depth2Image
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   514
             width:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   515
             height:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   516
             fromArray:#[
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   517
                            4r0123
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   518
                            4r1230
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   519
                            4r2301
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   520
                            4r3012
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   521
                        ])
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   522
            colorMap:(Array with:(Color black)
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   523
                            with:(Color red)
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   524
                            with:(Color green)
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   525
                            with:(Color blue));
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   526
            magnifiedBy:30
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   527
        ) edit
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   528
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   529
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   530
      depth8 image with 3/3/2 rgb interpretation:
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   531
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   532
        ((Depth8Image
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   533
             width:16
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   534
             height:16
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   535
             fromArray:(ByteArray withAll:(0 to:16rFF)))
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   536
            photometric:#rgb;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   537
            samplesPerPixel:3;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   538
            bitsPerSample:#(3 3 2);
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   539
            magnifiedBy:10
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   540
        ) edit
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   541
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   542
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   543
      depth8 image with 2/2/2 rgb interpretation:
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   544
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   545
        ((Depth8Image
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   546
             width:8
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   547
             height:8
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   548
             fromArray:(ByteArray withAll:(0 to:16r3F)))
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   549
            photometric:#rgb;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   550
            samplesPerPixel:3;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   551
            bitsPerSample:#(2 2 2);
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   552
            magnifiedBy:10
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   553
        ) edit
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   554
                                                                        [exEnd]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   555
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   556
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   557
        ((Depth8Image
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   558
             width:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   559
             height:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   560
             fromArray:#[
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   561
                    16r30 16r0C  16r03 16r3F
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   562
                    16r20 16r08  16r02 16r2A
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   563
                    16r10 16r04  16r01 16r15
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   564
                    16r00 16r00  16r00 16r00
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   565
                        ])
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   566
            photometric:#rgb;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   567
            samplesPerPixel:3;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   568
            bitsPerSample:#(2 2 2);
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   569
            magnifiedBy:30
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   570
        ) edit
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   571
                                                                        [exEnd]
5126
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   572
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   573
      trueColor image: remember: bytes are MSB
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   574
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   575
        ((Depth16Image
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   576
             width:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   577
             height:5
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   578
             fromArray:#[
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   579
                    2r01111100 2r00000000  2r00000011 2r11100000  2r00000000 2r00011111  2r01111111 2r11111111
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   580
                    2r00111100 2r00000000  2r00000001 2r11100000  2r00000000 2r00001111  2r00111101 2r11101111
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   581
                    2r00011100 2r00000000  2r00000000 2r11100000  2r00000000 2r00000111  2r00011100 2r11100111
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   582
                    2r00001100 2r00000000  2r00000000 2r01100000  2r00000000 2r00000001  2r00001100 2r01100011
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   583
                    2r00000100 2r00000000  2r00000000 2r00100000  2r00000000 2r00000001  2r00000100 2r00100001
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   584
                        ])
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   585
            photometric:#rgb;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   586
            samplesPerPixel:3;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   587
            bitsPerSample:#(5 5 5);
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   588
            magnifiedBy:30
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   589
        ) edit
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   590
                                                                        [exEnd]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   591
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   592
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   593
        ((Depth24Image
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   594
             width:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   595
             height:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   596
             fromArray:#[
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   597
                    16rFF 16r00 16r00  16rFF 16r00 16r00  16rFF 16r00 16r00  16rFF 16r00 16r00
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   598
                    16r00 16rFF 16r00  16r00 16rFF 16r00  16r00 16rFF 16r00  16r00 16rFF 16r00
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   599
                    16r00 16r00 16rFF  16r00 16r00 16rFF  16r00 16r00 16rFF  16r00 16r00 16rFF
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   600
                    16rFF 16rFF 16rFF  16rFF 16rFF 16rFF  16rFF 16rFF 16rFF  16rFF 16rFF 16rFF
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   601
                        ])
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   602
            photometric:#rgb;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   603
            samplesPerPixel:3;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   604
            bitsPerSample:#(8 8 8);
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   605
            magnifiedBy:30
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   606
        ) edit
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   607
                                                                        [exEnd]
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   608
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   609
      32bit trueColor image:
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   610
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   611
        ((Depth32Image
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   612
             width:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   613
             height:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   614
             fromArray:#[
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   615
                    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
   616
                    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
   617
                    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
   618
                    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
   619
                        ])
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   620
            photometric:#rgb;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   621
            samplesPerPixel:4;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   622
            bitsPerSample:#(8 8 8 8);
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   623
            magnifiedBy:30
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   624
        ) edit
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   625
                                                                        [exEnd]
2760
94d2d524081b example added (24-bit image)
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   626
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   627
    storing - only a subset of formats (TIFF, XBM, XPM) currently support storing:
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   628
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   629
        |img|
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   630
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   631
        img := Image fromFile:'bitmaps/winBitmaps/okSmily_up.bmp' inPackage:'stx:goodies'.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   632
        img saveOn:'myImage.tiff'.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   633
        (Image fromFile:'myImage.tiff') inspect.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   634
        img saveOn:'myImage.gif'.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   635
        (Image fromFile:'myImage.gif') inspect.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   636
                                                                        [exEnd]
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   637
649
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   638
    magnifying (any factor):
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   639
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   640
        ((Image fromFile:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies')
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   641
            magnifiedTo:(48@48))
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   642
                inspect
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   643
                                                                        [exEnd]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   644
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   645
        ((Image fromFile:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies')
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   646
            magnifiedBy:0.7)
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   647
                inspect
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   648
                                                                        [exEnd]
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   649
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   650
    rotating (any angle in degrees clockwise):
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   651
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   652
        ((Image fromFile:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies')
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   653
            rotated:90)
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   654
                inspect
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   655
                                                                        [exEnd]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   656
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   657
        (((Image fromFile:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies')
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   658
            magnifiedBy:0.3@0.7) rotated:270)
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   659
                inspect
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   660
                                                                        [exEnd]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   661
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   662
        (((Image fromFile:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies')
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   663
            ) rotated:30)
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   664
                inspect
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   665
                                                                        [exEnd]
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   666
    negative:
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   667
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   668
        ((Image fromFile:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies')
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   669
            negative)
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   670
                inspect
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   671
                                                                        [exEnd]
7123
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   672
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   673
      depth32 image with 8+8+8+8 argb interpretation:
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   674
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   675
        ((Depth32Image
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   676
             width:4 height:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   677
             fromArray:#[
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   678
                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
   679
                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
   680
                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
   681
                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
   682
            photometric:#argb;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   683
            samplesPerPixel:4;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   684
            bitsPerSample:#(8 8 8 8);
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   685
            magnifiedBy:10
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   686
        ) edit
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   687
                                                                        [exEnd]
7123
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   688
7126
a81b992fd069 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7123
diff changeset
   689
      depth32 image with 8+8+8+8 rgba interpretation:
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   690
                                                                        [exBegin]
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   691
        ((Depth32Image
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   692
             width:4 height:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   693
             fromArray:#[
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   694
                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
   695
                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
   696
                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
   697
                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
   698
            photometric:#rgba;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   699
            samplesPerPixel:4;
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   700
            bitsPerSample:#(8 8 8 8);
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   701
            magnifiedBy:10
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   702
        ) edit
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
   703
                                                                        [exEnd]
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   704
"
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
examples_functionalImages
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   708
"
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   709
    Functional images (please read 'Functional Images' by Conal Elliot, Microsoft Research).
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
   710
    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
   711
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   712
    Plain x/y mapping:
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   713
                                                                        [exBegin]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   714
        |i|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   715
        i := Depth1Image extent:256@256.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   716
        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
   717
        i inspect.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   718
                                                                        [exEnd]
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   719
    Transformed x/y mapping:
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   720
                                                                        [exBegin]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   721
        |i f|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   722
        f := [:x :y | (x between:0.4 and:0.6) asInteger].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   723
        i := Depth1Image extent:256@256.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   724
        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
   725
        i inspect.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   726
                                                                        [exEnd]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   727
                                                                        [exBegin]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   728
        |i f|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   729
        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
   730
        i := Depth1Image extent:256@256.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   731
        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
   732
        i inspect.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   733
                                                                        [exEnd]
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   734
    Image based on polar coordinate:
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   735
                                                                        [exBegin]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   736
        |i f|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   737
        f := [:x :y | ((x@y) r * 10) asInteger bitAnd:1].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   738
        i := Depth1Image extent:256@256.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   739
        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
   740
        i inspect.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   741
                                                                        [exEnd]
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   742
    Grayscale image based on polar coordinate:
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   743
                                                                        [exBegin]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   744
        |i|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   745
        i := Depth8Image extent:256@256.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   746
        i photometric:#blackIs0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   747
        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
   748
        i inspect.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   749
                                                                        [exEnd]
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   750
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   751
    Taking another image as ''input''
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   752
                                                                        [exBegin]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   753
        |garfield f i h|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   754
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   755
        garfield := Image fromFile:'bitmaps/gifImages/garfield.gif' inPackage:'stx:goodies'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   756
        h := garfield height.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   757
        f := [:x :y | (garfield colorAtX:x y:h-y) rgbValue].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   758
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   759
        i := Depth24Image extent:garfield extent.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   760
        i pixelFunction:f.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   761
        i inspect.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   762
                                                                        [exEnd]
649
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   763
"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   764
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
   765
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   766
!Image class methodsFor:'initialization'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   767
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   768
addReader:aReaderClass suffix:aSuffix
5216
f7ec910cfce1 Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 5200
diff changeset
   769
    <resource: #obsolete>
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   770
    "register an additional image reader.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   771
     This is provided for subclasses, to regster themself when
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   772
     loaded (or from the startup scripts)"
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   773
1800
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   774
    self obsoleteMethodWarning.
1780
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   775
    self addReader:aReaderClass suffix:aSuffix mimeType:nil
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   776
!
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
addReader:aReaderClass suffix:aSuffix mimeType:mimeType
5216
f7ec910cfce1 Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 5200
diff changeset
   779
    <resource: #obsolete>
1780
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   780
    "register an additional image reader.
1800
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   781
     This interface is kept for backward compatibility.
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   782
     The knowledge has been concentrated in MIMETypes"
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   783
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   784
    self obsoleteMethodWarning.
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   785
    MIMETypes
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   786
        defineImageType:mimeType suffix:aSuffix reader:aReaderClass
1780
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   787
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   788
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   789
     Image addReader:GIFReader suffix:'gif'
1780
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   790
     Image addReader:GIFReader suffix:'gif' mimeType:'image/gif'
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   791
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   792
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   793
    "Modified: 30.6.1997 / 21:59:59 / cg"
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   794
!
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   795
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   796
fileFormats
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   797
    "return the collection of supported file formats.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   798
     The returned dictionary maps file-extensions to image reader classes."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   799
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   800
    ^ MIMETypes fileSuffixToImageReaderMapping
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   801
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
     Image fileFormats
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   804
    "
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   805
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   806
    "Modified: 30.6.1997 / 22:05:58 / cg"
100
1b0b86c77397 co !!:*
claus
parents: 89
diff changeset
   807
!
1b0b86c77397 co !!:*
claus
parents: 89
diff changeset
   808
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   809
flushDeviceImages
869
464ffa8c0c67 comment
Claus Gittinger <cg@exept.de>
parents: 861
diff changeset
   810
    "simply release all deviceForms"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   811
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   812
    Lobby do:[:anImage |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   813
        anImage release
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   814
    ]
869
464ffa8c0c67 comment
Claus Gittinger <cg@exept.de>
parents: 861
diff changeset
   815
464ffa8c0c67 comment
Claus Gittinger <cg@exept.de>
parents: 861
diff changeset
   816
    "Modified: 15.6.1996 / 15:45:02 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   817
!
48194c26a46c Initial revision
claus
parents:
diff changeset
   818
48194c26a46c Initial revision
claus
parents:
diff changeset
   819
initialize
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
   820
    "initialize class constants"
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
   821
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   822
    "setup tracker of known pictures"
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   823
    Lobby isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   824
        Lobby := Registry new.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   825
        ObjectMemory addDependent:self.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   826
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   827
        "/ define the algorithm to use for dithering -
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   828
        "/ supported values are:
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   829
        "/      #threshold
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   830
        "/      #ordered
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   831
        "/      #floydSteinberg
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   832
        "/      #burkes
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   833
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   834
        DitherAlgorithm := #floydSteinberg.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   835
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   836
        (Display notNil and:[Display hasGrayscales]) ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   837
            NumberOfDitherColors := 64
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   838
        ] ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   839
            "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
   840
            NumberOfDitherColors := 100
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   841
        ].
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
        "define reader classes"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   844
        self initializeFileFormatTable.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   845
        self initializeMIMETable.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   846
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   847
        CollectGarbageWhenRunningOutOfColors := false.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   848
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   849
        ImageErrorSignal := Error newSignalMayProceed:true.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   850
        ImageErrorSignal nameClass:self message:#imageErrorSignal.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   851
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   852
        ImageSaveErrorSignal := ImageErrorSignal newSignalMayProceed:true.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   853
        ImageSaveErrorSignal nameClass:self message:#imageSaveErrorSignal.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   854
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   855
        FileCreationErrorSignal := ImageSaveErrorSignal newSignalMayProceed:true.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   856
        FileCreationErrorSignal nameClass:self message:#fileCreationErrorSignal.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   857
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   858
        CannotRepresentImageSignal := ImageSaveErrorSignal newSignalMayProceed:true.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   859
        CannotRepresentImageSignal nameClass:self message:#cannotRepresentImageSignal.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   860
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   861
        ImageLoadErrorSignal := QuerySignal new.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   862
        ImageLoadErrorSignal nameClass:self message:#imageLoadErrorSignal.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   863
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   864
        ImageNotFoundQuerySignal := QuerySignal new.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   865
        ImageNotFoundQuerySignal nameClass:self message:#imageNotFoundQuerySignal.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   866
        ImageNotFoundQuerySignal parent:ImageLoadErrorSignal.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   867
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   868
        InformationLostQuerySignal := QuerySignal new.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   869
        InformationLostQuerySignal nameClass:self message:#informationLostQuerySignal.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   870
        InformationLostQuerySignal parent:ImageLoadErrorSignal.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   871
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   872
        BadImageFormatQuerySignal := QuerySignal new.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   873
        BadImageFormatQuerySignal nameClass:self message:#badImageFormatQuerySignal.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   874
        BadImageFormatQuerySignal parent:ImageLoadErrorSignal.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   875
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   876
        UnrepresentableColorSignal := ImageErrorSignal newSignalMayProceed:true.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   877
        UnrepresentableColorSignal nameClass:self message:#unrepresentableColorSignal.
386
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
   878
    ]
748
818c6312acd1 grey vs. gray
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   879
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
   880
    "Modified: / 18.5.1999 / 15:50:03 / cg"
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   881
!
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   882
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   883
initializeFileFormatTable
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   884
    "initialize a default table to map from file extension to reader class.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   885
     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
   886
     see the 'smalltalk.rc'/'display.rc' startup files for a real (full) map."
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   887
1814
5d413419cf51 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1802
diff changeset
   888
    MIMETypes notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   889
        MIMETypes imageReaderForSuffix:'xbm'  put:XBMReader.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   890
        MIMETypes imageReaderForSuffix:'tiff' put:TIFFReader.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   891
        MIMETypes imageReaderForSuffix:'gif'  put:GIFReader.
1814
5d413419cf51 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1802
diff changeset
   892
    ].
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   893
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   894
    "
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   895
     Image initializeFileFormatTable
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   896
    "
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   897
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   898
    "Modified: 30.6.1997 / 22:07:28 / cg"
1785
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   899
!
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   900
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   901
initializeMIMETable
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   902
    "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
   903
     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
   904
     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
   905
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   906
    MIMETypes notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   907
        MIMETypes mimeTypeForSuffix:'gif'       put:'image/gif'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   908
        MIMETypes mimeTypeForSuffix:'tiff'      put:'image/tiff'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   909
        MIMETypes mimeTypeForSuffix:'tif'       put:'image/tiff'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   910
        MIMETypes mimeTypeForSuffix:'xbm'       put:'image/x-xbitmap'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   911
        MIMETypes mimeTypeForSuffix:'xpm'       put:'image/x-xpixmap'.
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   912
    ].
1785
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
    "
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   915
     Image initializeMIMETable
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   916
    "
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   917
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   918
    "Created: 27.6.1997 / 16:43:48 / cg"
1815
50212910fc13 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   919
    "Modified: 21.7.1997 / 17:33:59 / cg"
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   920
!
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   921
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
   922
update:something with:aParameter from:changedObject
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   923
    "flush all device specific stuff when restarted from a snapshot"
48194c26a46c Initial revision
claus
parents:
diff changeset
   924
48194c26a46c Initial revision
claus
parents:
diff changeset
   925
    (something == #restarted) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   926
        self flushDeviceImages
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   927
    ]
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
   928
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
   929
    "Created: 21.6.1996 / 19:47:43 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   930
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
   931
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   932
!Image class methodsFor:'instance creation'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   933
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   934
extent:ext
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   935
    "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
   936
     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
   937
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   938
    ^ 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
   939
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   940
    "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
   941
    "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
   942
!
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   943
3023
cb063801decd more Squeak compatibility
ps
parents: 2980
diff changeset
   944
extent:ext depth:d
cb063801decd more Squeak compatibility
ps
parents: 2980
diff changeset
   945
    "ST-80 compatibility"
cb063801decd more Squeak compatibility
ps
parents: 2980
diff changeset
   946
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   947
    ^ self width:ext x height:ext y depth:d
3023
cb063801decd more Squeak compatibility
ps
parents: 2980
diff changeset
   948
!
cb063801decd more Squeak compatibility
ps
parents: 2980
diff changeset
   949
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   950
extent:ext depth:d antiAliasedPalette:aBasicColorArray bgColor:bgColor
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   951
    ^ 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
   952
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   953
    "
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   954
        |colorMap aaImgArray|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   955
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   956
        colorMap := Array with:Color white with:Color blue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   957
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   958
        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
   959
        aaImgArray last
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   960
            fillAntiAliasedArc:200@200
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   961
            radius:80
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   962
            from:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   963
            angle:360
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   964
            withColor:Color blue
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   965
            antiAliasedPalette:aaImgArray first
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   966
            startWith:aaImgArray second.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   967
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   968
        aaImgArray last inspect.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   969
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
        |colorMap aaImgArray|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   972
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   973
        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
   974
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   975
        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
   976
        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
   977
            colorDictionary:aaImgArray first
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   978
            blendStart:aaImgArray second.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   979
        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
   980
            colorDictionary:aaImgArray first
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   981
            blendStart:aaImgArray second.
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
        aaImgArray last inspect.
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   984
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   985
    "
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   986
!
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   987
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   988
extent:ext depth:d antiAliasedPalette:aBasicColorArray bgColor:bgColor mixedArray:mixedArray
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
   989
    |colorMap colorIndex colorDictionary tmpDic newImage|
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
   990
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   991
    colorMap := OrderedCollection new.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   992
    colorIndex := 0.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   993
    colorDictionary := Dictionary new.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   994
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   995
    aBasicColorArray do:[:aColor |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   996
        colorMap add:aColor.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   997
        colorIndex := colorIndex + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   998
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
   999
        tmpDic := Dictionary new.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1000
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1001
        mixedArray do:[:aFloat |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1002
            tmpDic at:aFloat put:colorIndex.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1003
            colorMap add:(aColor mixed:aFloat with:bgColor).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1004
            colorIndex := colorIndex + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1005
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1006
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1007
        colorDictionary at:aColor put:tmpDic.
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1008
    ].
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1009
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1010
    newImage := (self implementorForDepth:d) new.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1011
    newImage width:ext x height:ext y depth:d palette:colorMap.
5643
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1012
    newImage createPixelStore.
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1013
"/    emptyBits := ByteArray new:(newImage bytesPerRow * ext y).
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1014
"/    newImage bits:emptyBits.
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1015
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  1016
    ^ Array with:colorDictionary with:mixedArray first with:newImage
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  1017
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  1018
    "
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1019
        |colorMap aaImgArray|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1020
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1021
        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
  1022
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1023
        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
  1024
        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
  1025
            colorDictionary:aaImgArray first
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1026
            blendStart:aaImgArray second.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1027
        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
  1028
            colorDictionary:aaImgArray first
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1029
            blendStart:aaImgArray second.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1030
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1031
        aaImgArray last inspect.
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  1032
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  1033
 ###################
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  1034
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1035
        |colorMap aaImgArray|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1036
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1037
        colorMap := Array with:Color white with:Color blue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1038
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1039
        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
  1040
        aaImgArray last
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1041
            fillAntiAliasedArc:200@200
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1042
            radius:80
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1043
            from:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1044
            angle:360
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1045
            withColor:Color blue
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1046
            colorDictionary:aaImgArray first
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1047
            blendStart:aaImgArray second.
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1048
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1049
        aaImgArray last inspect.
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1050
    "
5643
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1051
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1052
    "Modified: / 02-11-2010 / 20:57:41 / cg"
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1053
    "Modified: / 31-01-2017 / 14:30:22 / stefan"
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1054
    "Modified (comment): / 31-01-2017 / 15:47:39 / stefan"
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1055
!
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1056
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1057
extent:ext depth:d bits:bits
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1058
    "ST-80 compatibility; assume 32-bit padding"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1059
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1060
    ^ self extent:ext depth:d bits:bits pad:32
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
  1061
!
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
  1062
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1063
extent:ext depth:d bits:bits pad:padding
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1064
    "ST-80 compatibility"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1065
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1066
    ^ self width:ext x height:ext y depth:d fromArray:bits pad:padding
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
  1067
!
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
  1068
1276
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1069
extent:ext depth:d bitsPerPixel:bpp palette:aColormap usingBits:bits
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1070
    "ST-80 compatibility"
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1071
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1072
    |img|
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1073
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1074
    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
  1075
    img colorMap:aColormap.
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1076
    ^ img
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1077
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1078
    "Created: 25.1.1997 / 03:50:22 / cg"
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1079
    "Modified: 25.1.1997 / 12:27:35 / cg"
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1080
!
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1081
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1082
extent:ext depth:d palette:aColormap
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1083
    "create & return a blank image of the given size.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1084
     ST-80 compatibility"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1085
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1086
    |newImage|
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1087
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1088
    newImage := (self implementorForDepth:d) new.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1089
    newImage width:ext x height:ext y depth:d palette:aColormap.
5643
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1090
    newImage createPixelStore.
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1091
"/    emptyBits := ByteArray new:(newImage bytesPerRow * ext y).
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1092
"/    newImage bits:emptyBits.
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1093
    ^ newImage
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1094
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1095
    "
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1096
     Image extent:16@16 depth:8 palette:nil
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1097
     Image extent:16@16 depth:4 palette:nil
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1098
     Image extent:16@16 depth:2 palette:nil
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1099
    "
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1100
5643
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1101
    "Created: / 06-03-1997 / 15:24:01 / cg"
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1102
    "Modified: / 02-11-2010 / 20:56:53 / cg"
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1103
    "Modified (format): / 31-01-2017 / 14:51:03 / stefan"
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1104
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1105
1070
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1106
extent:ext depth:d palette:aColormap bits:bits
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1107
    "ST-80 compatibility"
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1108
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1109
    ^ self extent:ext depth:d palette:aColormap bits:bits pad:16
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1110
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1111
    "Modified: 7.10.1996 / 11:32:16 / cg"
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1112
!
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1113
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1114
extent:ext depth:d palette:aColormap bits:bits pad:padding
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1115
    "ST-80 compatibility"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1116
1070
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1117
    |img|
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1118
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1119
    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
  1120
    img colorMap:aColormap.
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1121
    ^ img
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1122
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1123
    "Modified: 7.10.1996 / 11:32:00 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1124
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1125
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1126
extent:ext fromArray:bits offset:offset
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1127
    "ST-80 compatibility"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1128
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1129
    ^ self width:ext x height:ext y fromArray:bits
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1130
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1131
7637
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  1132
fromDeviceForm:aForm maskForm:aMaskFormOrNil
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  1133
    "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
  1134
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  1135
    |img|
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  1136
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  1137
    img := self newForDepth:aForm depth.
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  1138
    img fromDeviceForm:aForm maskForm:aMaskFormOrNil.
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  1139
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  1140
    ^ img 
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  1141
!
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  1142
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1143
fromForm:aForm
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1144
    "create & return an Image given a aForm"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1145
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1146
    ^ self fromSubForm:(0@0 extent:aForm extent) in:aForm
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1147
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1148
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1149
     |f|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1150
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1151
     f := Form width:16 height:16.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1152
     f clear.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1153
     f displayLineFromX:0 y:0 toX:15 y:15.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1154
     f inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1155
     (Image fromForm:f) inspect
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1156
    "
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1157
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1158
    "
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1159
     |f|
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1160
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1161
     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
  1162
     f clear.
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1163
     f paint:(Color red).
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1164
     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
  1165
     f paint:(Color green).
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1166
     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
  1167
     f inspect.
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1168
     (Image fromForm:f) inspect
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1169
    "
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1170
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
  1171
    "Modified: 11.7.1996 / 11:21:42 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1172
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1173
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1174
fromImage:anImage
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1175
    "create & return an Image given another image. This can be used to
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1176
     convert an image to another depth."
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1177
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1178
    ^ 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
  1179
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1180
    "
3448
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1181
     |i i2 idx|
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1182
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1183
     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
  1184
     i2 := i deepCopy.
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1185
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1186
     idx := i2 colorMap indexOfPaintNearest:(Color green).
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1187
     i2 colorMap at:idx put:Color red.
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1188
     i2 inspect.
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1189
     i inspect.
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1190
    "
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1191
!
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
fromImage:anImage photometric:photometricOrNil
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1194
    "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
  1195
     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
  1196
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1197
    (self == Image
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1198
    or:[anImage class == self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1199
        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
  1200
    ^ self new fromImage:anImage photometric:photometricOrNil.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1201
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1202
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1203
     |i1 i8|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1204
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  1205
     i1 := Image fromFile:'goodies/bitmaps/SBrowser.xbm'.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1206
     i8 := Depth8Image fromImage:i1.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1207
     i8 inspect
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1208
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1209
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1210
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1211
fromSubForm:aRectangle in:aForm
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1212
    "create & return an subImage given a aForm"
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1213
7271
3d35b4e39ec4 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7242
diff changeset
  1214
    |depth formsDevice vis img photometric|
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1215
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1216
    depth := aForm depth.
7271
3d35b4e39ec4 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7242
diff changeset
  1217
    formsDevice := aForm device.
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1218
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1219
    photometric := (depth > 8) ifTrue:[#rgb] ifFalse:[#palette].
4937
1b0ebaed9336 photometric fix
Claus Gittinger <cg@exept.de>
parents: 4893
diff changeset
  1220
7271
3d35b4e39ec4 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7242
diff changeset
  1221
    (formsDevice notNil and:[depth == formsDevice depth]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1222
        "/
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1223
        "/ for truecolor displays, return a Depth24Image
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1224
        "/ (must do this for depth15 & depth16 displays, since
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1225
        "/  Depth16Image has no way to specify r/g/b masks ...)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1226
        "/
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1227
        vis := formsDevice visualType.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1228
        (vis == #TrueColor or:[vis == #DirectColor]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1229
            depth > 8 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1230
                depth := 24.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1231
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1232
        ].
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1233
    ].
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1234
    img := self newForDepth:depth.
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1235
    img photometric:photometric.
4937
1b0ebaed9336 photometric fix
Claus Gittinger <cg@exept.de>
parents: 4893
diff changeset
  1236
7271
3d35b4e39ec4 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7242
diff changeset
  1237
    formsDevice isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1238
        ^ img from:aForm in:aRectangle.
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1239
    ].
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1240
    ^ img from:aForm in:aRectangle
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1241
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1242
    "
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1243
     |f|
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1244
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1245
     f := Form width:16 height:16.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1246
     f clear.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1247
     f displayLineFromX:0 y:0 toX:15 y:15.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1248
     f inspect.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1249
     (Image fromForm:f) inspect.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1250
     (Image fromSubForm:(5@5 corner:10@10) in:f) inspect
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1251
    "
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
    "
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1254
     |f|
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 := Form width:16 height:16 depth:(Display depth) on:Display.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1257
     f clear.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1258
     f paint:(Color red).
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1259
     f displayLineFromX:0 y:0 toX:15 y:15.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1260
     f paint:(Color green).
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1261
     f displayLineFromX:15 y:0 toX:0 y:15.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1262
     f inspect.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1263
     (Image fromForm:f) inspect.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1264
     (Image fromSubForm:(5@5 corner:10@10) in:f) inspect
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1265
    "
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1266
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1267
    "Modified: / 31-01-2017 / 15:03:17 / stefan"
3026
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
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1270
fromSubImage:anImage in:aRectangle
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1271
    "create & return an Image from a rectangular area in another image.
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1272
     This can also be used to get a subimage in another depth.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1273
     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
  1274
     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
  1275
     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
  1276
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1277
    |cls|
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1278
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1279
    self == Image ifTrue:[
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  1280
        cls := self implementorForDepth:anImage depth.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1281
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1282
        cls := self.
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1283
    ].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1284
    ^ cls new fromSubImage:anImage in:aRectangle.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1285
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1286
    "
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1287
     |i1 i8|
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1288
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1289
     i1 := Image fromFile:'bitmaps/gifImages/garfield.gif' inPackage:'stx:goodies'.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1290
     i8 := Depth8Image fromSubImage:i1 in:(250@90 extent:50@50).
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1291
     i8 inspect
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1292
    "
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1293
    "
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1294
     |i1 i8|
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1295
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1296
     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
  1297
     i8 := Image fromSubImage:i1 in:(70@50 extent:50@50).
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1298
     i8 inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1299
    "
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1300
    "
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1301
     |i1 i24|
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1302
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1303
     i1 := Image fromFile:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies'.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1304
     i24 := Depth24Image fromSubImage:i1 in:(70@50 extent:50@50).
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1305
     i24 inspect
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1306
    "
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1307
    "
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1308
     |i1 i24|
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1309
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1310
     i1 := Image fromFile:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies'.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1311
     i1 inspect.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1312
     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
  1313
     i24 inspect
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1314
    "
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1315
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  1316
    "Created: / 20-09-1995 / 01:05:43 / claus"
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  1317
    "Modified: / 24-04-1997 / 23:13:02 / cg"
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  1318
    "Modified (format): / 30-01-2017 / 19:45:54 / stefan"
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1319
!
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1320
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1321
new
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1322
    "create a new image. Redefined to set the photometric to
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1323
     greyScale with black being 0 as default."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1324
4416
fb209558d622 proper #initialize
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
  1325
    ^ self basicNew initialize
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1326
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1327
    "Modified: 10.6.1996 / 18:08:37 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1328
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1329
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1330
newForDepth:depth
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1331
    "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
  1332
     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
  1333
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1334
    |cls|
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1335
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1336
    cls := self implementorForDepth:depth.
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1337
    ^ cls new
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1338
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1339
    "
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1340
     Image newForDepth:8
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1341
    "
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1342
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1343
    "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
  1344
!
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1345
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1346
width:w height:h
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1347
    "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
  1348
     Assume a depth of 1, unless an explicit imageClass is the receiver."
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1349
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1350
    |cls|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1351
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1352
    cls := self.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1353
    cls == Image ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1354
        cls := self implementorForDepth:1
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  1355
    ].
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  1356
    ^ cls new width:w height:h
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  1357
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  1358
    "Modified: / 06-06-2007 / 11:10:55 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1359
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1360
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1361
width:w height:h depth:d
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1362
    "create a new image, given width, height and depth"
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1363
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1364
    ^ (self newForDepth:d)
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1365
        width:w height:h depth:d
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1366
!
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1367
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1368
width:w height:h depth:d fromArray:pixelData
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1369
    "create a new image, given width, height, depth and data.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1370
     Data must be a ByteArray containing correctly aligned bits for the specified
134
claus
parents: 132
diff changeset
  1371
     depth (8-bit padded)."
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1372
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1373
    ^ (self newForDepth:d)
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1374
        width:w height:h depth:d fromArray:pixelData
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1375
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1376
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1377
     Image width:8
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1378
           height:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1379
           depth:1
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1380
           fromArray:#[2r11001100
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1381
                       2r00110011
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1382
                       2r11001100
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1383
                       2r00110011
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1384
                       2r11001100
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1385
                       2r00110011
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1386
                       2r11001100
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1387
                       2r00110011].
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1388
    "
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1389
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1390
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1391
     Image width:8
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1392
           height:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1393
           depth:2
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1394
           fromArray:#[4r1100 4r1100
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1395
                       4r0011 4r0011
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1396
                       4r1100 4r1100
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1397
                       4r0011 4r0011
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1398
                       4r1100 4r1100
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1399
                       4r0011 4r0011
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1400
                       4r1100 4r1100
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1401
                       4r0011 4r0011].
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1402
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1403
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1404
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1405
     Image width:8
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1406
           height:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1407
           depth:4
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1408
           fromArray:#[16r00 16r01 16rf0 16rf1
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1409
                       16r02 16r03 16rf2 16rf3
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1410
                       16r04 16r05 16rf4 16rf5
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1411
                       16r06 16r07 16rf6 16rf7
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1412
                       16r08 16r09 16rf8 16rf9
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1413
                       16r0a 16r0b 16rfa 16rfb
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1414
                       16r0c 16r0d 16rfc 16rfd
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1415
                       16r0e 16r0f 16rfe 16rff].
7101
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1416
    "
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1417
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1418
    "
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1419
     Image width:8
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1420
           height:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1421
           depth:16
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1422
           fromArray:#(1 1 1 1 1 1 1 1
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1423
                       2 2 2 2 2 2 2 2
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1424
                       3 3 3 3 3 3 3 3
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1425
                       4 4 4 4 4 4 4 4
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1426
                       5 5 5 5 5 5 5 5
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1427
                       6 6 6 6 6 6 6 6
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1428
                       7 7 7 7 7 7 7 7
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1429
                       8 8 8 8 8 8 8 8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1430
                      ) asWordArray.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1431
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1432
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1433
    "Modified: 10.6.1996 / 18:18:10 / cg"
132
claus
parents: 125
diff changeset
  1434
!
claus
parents: 125
diff changeset
  1435
134
claus
parents: 132
diff changeset
  1436
width:w height:h depth:d fromArray:pixelData pad:padding
claus
parents: 132
diff changeset
  1437
    "create a new image, given width, height, depth and data.
claus
parents: 132
diff changeset
  1438
     Data must be a ByteArray containing correctly aligned bits for the specified
claus
parents: 132
diff changeset
  1439
     depth."
claus
parents: 132
diff changeset
  1440
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1441
    |img newBits
2772
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  1442
     srcRowBytes "{ Class: SmallInteger }"
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  1443
     dstRowBytes "{ Class: SmallInteger }"
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  1444
     nextDstIndex "{ Class: SmallInteger }"
2527
5391e6e2c8a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2526
diff changeset
  1445
     srcIndex "{ Class: SmallInteger }"
5391e6e2c8a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2526
diff changeset
  1446
     dstIndex "{ Class: SmallInteger }" |
134
claus
parents: 132
diff changeset
  1447
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1448
    img := (self newForDepth:d) width:w height:h depth:d .
134
claus
parents: 132
diff changeset
  1449
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1450
    srcRowBytes := ((w * d + padding - 1) bitShift:-5) bitShift:2.
5341
ede63c3764ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5326
diff changeset
  1451
    dstRowBytes := img bytesPerRow.
ede63c3764ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5326
diff changeset
  1452
ede63c3764ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5326
diff changeset
  1453
    (padding ~~ 8 and:[(srcRowBytes \\ 4 ~~ 0) or:[srcRowBytes ~= dstRowBytes]]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1454
        "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
  1455
         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
  1456
        "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1457
        dstRowBytes := img bytesPerRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1458
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1459
        newBits := ByteArray uninitializedNew:(dstRowBytes * h).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1460
        srcIndex := 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1461
        dstIndex := 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1462
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1463
        1 to:h do:[:row |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1464
            nextDstIndex := dstIndex + dstRowBytes.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1465
            newBits replaceFrom:dstIndex
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1466
                             to:(nextDstIndex - 1)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1467
                           with:pixelData
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1468
                     startingAt:srcIndex.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1469
            srcIndex := srcIndex + srcRowBytes.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1470
            dstIndex := nextDstIndex.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1471
        ].
134
claus
parents: 132
diff changeset
  1472
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1473
        pixelData class isBytes ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1474
            newBits := ByteArray withAll:pixelData
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1475
        ] ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1476
            newBits := pixelData
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1477
        ]
134
claus
parents: 132
diff changeset
  1478
    ].
claus
parents: 132
diff changeset
  1479
    img bits:newBits.
claus
parents: 132
diff changeset
  1480
    ^ img
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1481
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1482
    "Modified: / 27-05-2007 / 14:01:32 / cg"
134
claus
parents: 132
diff changeset
  1483
!
claus
parents: 132
diff changeset
  1484
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1485
width:w height:h fromArray:anArray
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1486
    "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
  1487
     receiving class is Image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1488
     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
  1489
     (i.e. 8 bits per byte)."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1490
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1491
    |cls d pixels|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1492
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1493
    cls := self.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1494
    cls == Image ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1495
        cls := self implementorForDepth:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1496
        d := 1.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1497
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1498
        d := cls imageDepth
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1499
    ].
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1500
    anArray class isBytes ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1501
        pixels := ByteArray withAll:anArray
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1502
    ] ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1503
        pixels := anArray
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1504
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1505
    ^ cls new width:w height:h depth:d fromArray:pixels
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1506
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1507
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1508
     Image width:8
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1509
           height:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1510
           fromArray:#[2r11001100
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1511
                       2r00110011
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1512
                       2r11001100
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1513
                       2r00110011
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1514
                       2r11001100
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1515
                       2r00110011
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1516
                       2r11001100
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1517
                       2r00110011].
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1518
    "
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1519
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1520
    "Modified: 8.6.1996 / 10:07:26 / cg"
6899
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1521
!
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1522
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1523
width:w height:h photometric:photometric
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1524
    "create a new image, given width, height.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1525
     Assume a depth of 1, unless an explicit imageClass is the receiver."
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1526
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1527
    |cls|
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1528
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1529
    cls := self.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1530
    cls == Image ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1531
        cls := self implementorForDepth:1
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1532
    ].
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1533
    ^ cls new width:w height:h; photometric:photometric; yourself
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1534
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1535
    "Modified: / 06-06-2007 / 11:10:55 / cg"
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1536
!
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1537
6899
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1538
width:w height:h photometric:photometric bitsPerSample:bitsPerSample
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1539
    "create a new image, given width, height.
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1540
     Assume a depth of 1, unless an explicit imageClass is the receiver."
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1541
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1542
    |cls|
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1543
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1544
    cls := self.
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1545
    cls == Image ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1546
        cls := self implementorForDepth:1
6899
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1547
    ].
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1548
    ^ cls new width:w height:h; photometric:photometric; bitsPerSample:bitsPerSample; yourself
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1549
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1550
    "Modified: / 06-06-2007 / 11:10:55 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1551
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1552
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1553
!Image class methodsFor:'Signal constants'!
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1554
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1555
badImageFormatQuerySignal
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1556
    "return the (query-) signal, which is raised if some
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1557
     bitmap-image could not be loaded due to an unrecognized format.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1558
     If unhandled, the image-load returns nil.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1559
     Otherwise, it returns whatever the handler proceeds with.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1560
     The exception gets either the images fileName or an input stream
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1561
     as parameter"
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1562
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1563
    ^ BadImageFormatQuerySignal
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1564
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1565
    "Created: 1.2.1997 / 14:40:29 / cg"
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1566
!
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1567
1385
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1568
cannotRepresentImageSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1569
    "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
  1570
     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
  1571
     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
  1572
     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
  1573
     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
  1574
     (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
  1575
     format then."
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1576
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1577
    ^ CannotRepresentImageSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1578
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1579
    "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
  1580
!
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1581
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1582
fileCreationErrorSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1583
    "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
  1584
     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
  1585
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1586
    ^ FileCreationErrorSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1587
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1588
    "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
  1589
!
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1590
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1591
imageErrorSignal
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1592
    "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
  1593
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1594
    ^ ImageErrorSignal
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1595
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1596
    "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
  1597
!
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1598
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1599
imageLoadErrorSignal
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1600
    "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
  1601
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1602
    ^ ImageLoadErrorSignal
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1603
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1604
    "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
  1605
!
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1606
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1607
imageNotFoundQuerySignal
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1608
    "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
  1609
     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
  1610
     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
  1611
     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
  1612
     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
  1613
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1614
    ^ ImageNotFoundQuerySignal
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1615
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1616
    "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
  1617
!
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1618
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1619
imageSaveErrorSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1620
    "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
  1621
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1622
    ^ ImageSaveErrorSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1623
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1624
    "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
  1625
!
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1626
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1627
informationLostQuerySignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1628
    "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
  1629
     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
  1630
     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
  1631
     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
  1632
     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
  1633
     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
  1634
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1635
    ^ InformationLostQuerySignal
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:43:50 / cg"
2182
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1638
!
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1639
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1640
unrepresentableColorSignal
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1641
    "return the signal, which is raised if some color is not
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1642
     representable in the image (when storing a pixel)."
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1643
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1644
    ^ UnrepresentableColorSignal
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1645
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1646
    "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
  1647
! !
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1648
1230
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1649
!Image class methodsFor:'cleanup'!
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1650
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1651
releaseResourcesOnDevice:aDevice
1230
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1652
    "this is sent when a display connection is closed,
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1653
     to release all cached Images from that device"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1654
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1655
    Lobby
7565
462e6f62c737 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 7552
diff changeset
  1656
        unregisterAllForWhichHandle:[:eachImage |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1657
            |ok|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1658
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1659
            ok := eachImage graphicsDevice == aDevice.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1660
            ok ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1661
                eachImage releaseFromDevice
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1662
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1663
            ok
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1664
        ].
6390
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
  1665
7573
656c59bc93ad #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7565
diff changeset
  1666
    Icon notNil ifTrue:[
656c59bc93ad #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7565
diff changeset
  1667
        Icon releaseCachedIconsFromDevice:aDevice.
656c59bc93ad #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7565
diff changeset
  1668
    ].
656c59bc93ad #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7565
diff changeset
  1669
    MenuPanel notNil ifTrue:[
656c59bc93ad #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7565
diff changeset
  1670
        MenuPanel releaseCachedImagesFromDevice:aDevice.
656c59bc93ad #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7565
diff changeset
  1671
    ].
656c59bc93ad #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7565
diff changeset
  1672
656c59bc93ad #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7565
diff changeset
  1673
6390
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
  1674
    "
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
  1675
      self releaseResourcesOnDevice:Screen current
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
  1676
    "
1230
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1677
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1678
    "Created: 16.1.1997 / 19:30:44 / cg"
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1679
    "Modified: 16.1.1997 / 19:33:49 / cg"
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1680
! !
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1681
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  1682
!Image class methodsFor:'file reading'!
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1683
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1684
fromFile:aFileName
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1685
    "read an image from a file - this methods tries to find
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1686
     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
  1687
     and lets the appropriate reader read the file.
6375
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1688
     Also, unless the path is absolute,
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1689
     all bitmap directories along the searchPath are checked
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1690
     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
  1691
     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
  1692
     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
  1693
     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
  1694
     proceed with some replacement image. If unhandled, nil is returned."
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1695
6532
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1696
    |image fn nm inStream suffix readerClass
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1697
     mustDecompress readersErrorMsg|
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1698
4159
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1699
    "before trying each reader, check if the file is readable"
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1700
6532
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1701
    fn := aFileName asFilename.
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1702
    fn isAbsolute ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1703
        inStream := Smalltalk systemFileStreamFor:fn.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1704
        inStream isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1705
            inStream := Smalltalk bitmapFileStreamFor:fn.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1706
            inStream isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1707
                "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
  1708
                 However, a handler may provide a replacement image."
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1709
                ^ ImageNotFoundQuerySignal
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1710
                            raiseRequestWith:fn
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1711
                            errorString:('Image: ''' , fn pathName, ''' does not exist or is not readable').
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1712
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1713
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1714
        fn := inStream pathName asFilename.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1715
        inStream close.
4843
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1716
    ].
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1717
4158
930761d24ab2 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4156
diff changeset
  1718
    nm := fn name.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1719
    suffix := fn suffix.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1720
4159
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1721
    "handle compressed-suffix"
6532
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1722
    (#('gz') includes:suffix) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1723
        |baseFn|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1724
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1725
        baseFn := fn withoutSuffix.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1726
        nm := baseFn name.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1727
        suffix := baseFn suffix.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1728
        mustDecompress := true.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1729
    ].
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1730
    suffix isEmpty ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1731
        suffix := nm.
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
  1732
    ].
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
  1733
6507
05fb9b9d9e53 class: Image
Claus Gittinger <cg@exept.de>
parents: 6496
diff changeset
  1734
    "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
  1735
    readerClass := MIMETypes imageReaderForSuffix:suffix.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1736
    readerClass notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1737
        mustDecompress == true ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1738
            |zipStream|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1739
            inStream := fn readStream.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1740
            zipStream := ZipStream readOpenOn:inStream suppressHeaderAndChecksum:true.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1741
            zipStream notNil ifTrue:[
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  1742
                image := [
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  1743
                    readerClass fromStream:zipStream.
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1744
                ] ensure:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1745
                    zipStream close.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1746
                    inStream close.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1747
                ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1748
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1749
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1750
            BadImageFormatQuerySignal handle:[:ex |
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1751
                BadImageFormatQuerySignal isHandled ifTrue:[
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1752
                    ex reject
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1753
                ].
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1754
                readersErrorMsg := ex description.
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1755
                Logger warning:readersErrorMsg.
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1756
                image := nil.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1757
                ex return.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1758
            ] do:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1759
                image := readerClass fromFile:fn.
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
        image notNil ifTrue:[^ image].
4159
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1763
    ].
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1764
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1765
    (readerClass isNil or:[readersErrorMsg notNil]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1766
        "no known extension (or wrong extension)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1767
         - ask all readers if they know this format ...
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1768
         ... these look into the file, and investigate the header.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1769
         therefore, it takes a bit longer."
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1770
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1771
        MIMETypes imageReaderClasses do:[:mimeReaderClass |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1772
            (mimeReaderClass notNil
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1773
            and:[mimeReaderClass ~~ readerClass]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1774
               (mimeReaderClass isValidImageFile:fn) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1775
                    image := mimeReaderClass fromFile:fn.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1776
                    image notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1777
                        ^ image
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1778
                    ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1779
                ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1780
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1781
        ].
4159
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1782
    ].
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1783
7175
4bd37cf4075e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7173
diff changeset
  1784
    (fn exists and:[fn isReadable]) ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1785
        ^ ImageNotFoundQuerySignal
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1786
                    raiseRequestWith:fn
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1787
                    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
  1788
    ].
61933c223183 added metaData instVar (for free use by image reader)
Claus Gittinger <cg@exept.de>
parents: 7363
diff changeset
  1789
4159
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1790
    "nope - unknown format
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1791
     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
  1792
     However, a handler may provide a replacement image."
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1793
3656
11670e0e6fcb invalid format notification fixed
Claus Gittinger <cg@exept.de>
parents: 3623
diff changeset
  1794
    ^ BadImageFormatQuerySignal
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1795
        raiseRequestWith:fn
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1796
        errorString:(readersErrorMsg ? ('Image: unknown image file format: ''' , fn pathName , '''')).
4159
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1797
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1798
    "
6532
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1799
     Image fromFile:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies'
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1800
     Image fromFile:'bitmaps/gifImages/garfield.gif' inPackage:'stx:goodies'
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1801
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1802
     Image fromFile:'bitmaps/winBitmaps/a11.ico' inPackage:'stx:goodies'
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1803
     Image fromFile:'bitmaps/xpmBitmaps/countries/czech.xpm' inPackage:'stx:goodies'
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1804
     Image fromFile:'bitmaps/xpmBitmaps/countries/czech.xpm.gz' inPackage:'stx:goodies'
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1805
     Image fromFile:'Demos/bitmaps/hello_world.icon' inPackage:'stx:clients'
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1806
    "
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1807
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1808
    "
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1809
     Image fromFile:'fooBar'
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1810
    "
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1811
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
  1812
    "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
  1813
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1814
     Image imageNotFoundQuerySignal
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1815
     handle:[:ex |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1816
        Transcript showCR:ex description.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1817
        ex proceedWith:nil
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1818
     ] do:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1819
         Image fromFile:'fooBar'
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1820
     ]
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
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1823
    "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
  1824
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1825
     Image imageNotFoundQuerySignal
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
  1826
     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
  1827
     do:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1828
         Image fromFile:'fooBar'
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1829
     ]
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1830
    "
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1831
4843
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1832
    "Modified: / 19-11-2007 / 15:50:52 / cg"
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1833
    "Modified: / 31-01-2017 / 15:56:14 / stefan"
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1834
!
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1835
3426
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1836
fromFile:aFileName inPackage:aPackage
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1837
    "read an image for a package from a file.
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1838
     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
  1839
     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
  1840
     and lets the appropriate reader read the file.
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1841
     Also, all bitmap directories along the searchPath are checked
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1842
     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
  1843
     separate directory, thereby overriding system bitmaps easily.
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1844
     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
  1845
     the ImageNotFoundQuerySignal is raised, which may be handled to
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1846
     proceed with some replacement image. If unhandled, nil is returned."
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1847
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1848
    ^ Smalltalk imageFromFileNamed:aFileName inPackage:aPackage
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1849
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1850
    "
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1851
     Image fromFile:'libtool/bitmaps/SBrowser.xbm'
3426
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1852
     Image fromFile:'bitmaps/SBrowser.xbm' inPackage:'stx:libtool'
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1853
     Image fromFile:'garfield.gif' inPackage:'stx:goodies/bitmaps/gifImages'
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1854
    "
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1855
!
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1856
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1857
fromFile:aFileName on:aDevice
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1858
    "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
  1859
     Return nil (or whatever a handler returned),
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1860
     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
  1861
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1862
    |img|
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1863
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1864
    img := self fromFile:aFileName.
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1865
    img notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1866
        ^ img onDevice:aDevice
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1867
    ].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1868
    ^ nil
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1869
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1870
    "Modified: 1.2.1997 / 14:48:07 / cg"
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1871
!
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1872
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1873
fromFile:aFileName resolution:res
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1874
    "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
  1875
     as appropriate (only req'd for very high resolution displays).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1876
     Return nil (or whatever a handler returned),
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1877
     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
  1878
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1879
    ^ self fromFile:aFileName resolution:res on:nil
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1880
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1881
    "Created: 19.12.1996 / 14:02:13 / cg"
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1882
    "Modified: 1.2.1997 / 14:48:16 / cg"
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1883
!
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1884
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1885
fromFile:aFileName resolution:dpi on:aDevice
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1886
    "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
  1887
     as appropriate (only req'd with very high resolution displays).
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1888
     Prepare a device representation.
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
    |img dev dpiH mag|
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1893
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1894
    img := self fromFile:aFileName.
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1895
    img isNil ifTrue:[^ nil].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1896
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1897
    "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
  1898
    dev := aDevice.
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1899
    dev isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1900
        "should not happen ..."
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1901
        dev := Screen current
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1902
    ].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1903
3059
0895d23678ac assume 90dpi in #fromFile:resolution: if there is no current display
Claus Gittinger <cg@exept.de>
parents: 3038
diff changeset
  1904
    dev notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1905
        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
  1906
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1907
        dpiH := 90
3059
0895d23678ac assume 90dpi in #fromFile:resolution: if there is no current display
Claus Gittinger <cg@exept.de>
parents: 3038
diff changeset
  1908
    ].
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1909
    (dpi between:(dpiH * 0.75) and:(dpiH * 1.5)) ifTrue:[
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1910
        ^ img
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1911
    ].
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1912
    mag := (dpiH / dpi) rounded.
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1913
    mag = 0 ifTrue:[^ img].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1914
    mag = 1 ifTrue:[^ img].
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
    img := img magnifiedBy:(mag @ mag).
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1917
    aDevice notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1918
        ^ img onDevice:aDevice
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1919
    ].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1920
    ^ img
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1921
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1922
    "Modified: / 01-02-1997 / 14:48:20 / cg"
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  1923
    "Modified (format): / 31-01-2017 / 15:06:23 / stefan"
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1924
!
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1925
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1926
fromStream:aStream
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1927
    "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
  1928
     out the file format itself (by contents)
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1929
     and lets the appropriate reader read the file.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1930
     To do this, the stream must be positionable.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1931
     Return nil (or whatever a handler returned),
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1932
     if the stream does not contain an appropriate image."
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1933
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  1934
    |image|
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1935
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1936
    "
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1937
     ask all readers if they know
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1938
     this format ...
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1939
    "
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  1940
    MIMETypes imageReaderClasses do:[:readerClass |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1941
        readerClass notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1942
            image := readerClass fromStream:aStream.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1943
            image notNil ifTrue:[^ image].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1944
        ]
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1945
    ].
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1946
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1947
    "
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1948
     nope - unknown format
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1949
    "
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1950
"/    'Image [info]: unknown image file format in stream: ' infoPrintCR.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1951
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1952
    ^ ImageNotFoundQuerySignal
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1953
                raiseRequestWith:aStream
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1954
                errorString:('Image [warning]: unknown image file format in stream').
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1955
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1956
    "
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1957
     Image fromFile:'goodies/bitmaps/gifImages/claus.gif'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1958
     Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1959
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1960
     Image fromFile:'clients/Animation/bitmaps/globe1.xbm'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1961
     Image fromFile:'clients/Animation/bitmaps/globe1.xbm.Z'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1962
     Image fromFile:'clients/Demos/bitmaps/hello_world.icon'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1963
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1964
     Image fromFile:'librun/stx.ico'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1965
     Image fromFile:'libwidg3/bitmaps/wall.tiff'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1966
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  1967
     Image fromFile:'goodies/bitmaps/test.fax'
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1968
     Image fromFile:'fileIn/bitmaps/founders.im8'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1969
     Image fromFile:'goodies/faces/next.com/steve.face'
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1970
    "
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1971
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1972
    "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
  1973
    "Modified: 30.6.1997 / 22:03:59 / cg"
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1974
!
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1975
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1976
fromStream:aStream using:aReaderClass
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1977
    "read an image from a stream, given an imageReaderClass.
6507
05fb9b9d9e53 class: Image
Claus Gittinger <cg@exept.de>
parents: 6496
diff changeset
  1978
     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
  1979
     extension (or non-definite header), so #fromStream: could not
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1980
     find out the images format.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1981
     Return nil (or whatever a handler returned),
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1982
     if the stream does not contain an appropriate image."
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1983
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1984
    |image|
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1985
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1986
    image := aReaderClass fromStream:aStream.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1987
    image notNil ifTrue:[^ image].
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
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1990
     nope - unknown format
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1991
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1992
"/    'Image [info]: unknown image file format in stream: ' infoPrintCR.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1993
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1994
    ^ ImageNotFoundQuerySignal
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1995
                raiseRequestWith:aStream
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1996
                errorString:('Image: unknown image file format in stream').
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1997
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1998
    "Created: 1.2.1997 / 14:46:20 / cg"
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1999
    "Modified: 1.2.1997 / 14:48:53 / cg"
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  2000
! !
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  2001
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  2002
!Image class methodsFor:'misc'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2003
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  2004
ditherAlgorithm
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2005
    "return the way we dither -
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2006
        #threshold, or nil        -> no dither
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2007
        #pattern, or #ordered     -> orderedDither (ugly, but fast)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2008
        #error or #floydSteinberg -> errorDiffusion; much better
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2009
        #burkes                   -> errorDiffusion; even better."
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  2010
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  2011
    ^ DitherAlgorithm
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  2012
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  2013
    "Created: 17.6.1996 / 18:57:47 / cg"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  2014
!
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  2015
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  2016
ditherAlgorithm:aSymbol
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2017
    "define how to dither -
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2018
        #threshold, or nil        -> no dither
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2019
        #pattern, or #ordered     -> orderedDither (ugly, but fast)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2020
        #error or #floydSteinberg -> errorDiffusion; much better
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2021
        #burkes                   -> errorDiffusion; even better."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2022
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2023
    DitherAlgorithm := aSymbol
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2024
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2025
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2026
     Image dither:#pattern
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2027
     Image dither:#floydSteinberg
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2028
     Image dither:#burkes
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2029
     Image dither:nil
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2030
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2031
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2032
    "Modified: 10.6.1996 / 12:27:09 / cg"
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  2033
    "Created: 17.6.1996 / 18:57:19 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2034
!
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
numberOfDitherColors:n
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2037
    "define how many colors (i.e. patterns) to use when
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2038
     doing a pattern dither"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2039
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2040
    NumberOfDitherColors := n
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2041
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2042
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2043
orderedDitherMatrixOfSize:sz
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2044
    sz == 2 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2045
        ^ #[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2046
                0 2
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2047
                3 1
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2048
           ].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2049
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2050
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2051
    sz == 4 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2052
        ^ #[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2053
                 0  8  2 10
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2054
                12  4 14  6
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2055
                 3 11  1  9
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2056
                15  7 13  5
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2057
           ].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2058
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2059
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2060
    sz == 8 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2061
        ^  #[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2062
                0 32  8 40    2 34 10 42
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2063
               48 16 56 24   50 18 58 26
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2064
               12 44  4 36   14 46  6 38
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2065
               60 28 52 20   62 30 54 22
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2066
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2067
                3 35 11 43    1 33  9 41
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2068
               51 19 59 27   49 17 57 25
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2069
               15 47  7 39   13 45  5 37
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2070
               63 31 55 23   61 29 53 21
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2071
            ].
798
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
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2074
    ^ nil
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2075
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2076
    "Created: 7.6.1996 / 14:15:05 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2077
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2078
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  2079
!Image class methodsFor:'queries'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2080
2005
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2081
bytesPerRowForWidth:width depth:bitsPerPixel padding:padding
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2082
    "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
  2083
     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
  2084
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2085
    |bitsPerRow paddedUnitsPerRow|
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2086
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2087
    bitsPerRow := width * bitsPerPixel.
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2088
    paddedUnitsPerRow := bitsPerRow // padding.
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2089
    ((bitsPerRow \\ padding) ~~ 0) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2090
        paddedUnitsPerRow := paddedUnitsPerRow + 1
2005
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2091
    ].
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2092
    ^ paddedUnitsPerRow * (padding // 8)
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2093
5126
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  2094
    "
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  2095
     self bytesPerRowForWidth:7 depth:1 padding:8
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  2096
     self bytesPerRowForWidth:7 depth:1 padding:16
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  2097
     self bytesPerRowForWidth:7 depth:1 padding:32
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  2098
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  2099
     self bytesPerRowForWidth:15 depth:1 padding:8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  2100
     self bytesPerRowForWidth:15 depth:1 padding:16
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  2101
     self bytesPerRowForWidth:15 depth:1 padding:32
5126
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  2102
    "
2005
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2103
!
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2104
6797
161685b0d113 class: Image
Claus Gittinger <cg@exept.de>
parents: 6755
diff changeset
  2105
defaultImageFileWriter
161685b0d113 class: Image
Claus Gittinger <cg@exept.de>
parents: 6755
diff changeset
  2106
    "only used, if a file is saved with no particular extension
161685b0d113 class: Image
Claus Gittinger <cg@exept.de>
parents: 6755
diff changeset
  2107
     or explicit writer given.
161685b0d113 class: Image
Claus Gittinger <cg@exept.de>
parents: 6755
diff changeset
  2108
     For now, default to tiff format.
161685b0d113 class: Image
Claus Gittinger <cg@exept.de>
parents: 6755
diff changeset
  2109
     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
  2110
161685b0d113 class: Image
Claus Gittinger <cg@exept.de>
parents: 6755
diff changeset
  2111
    ^ TIFFReader
161685b0d113 class: Image
Claus Gittinger <cg@exept.de>
parents: 6755
diff changeset
  2112
!
161685b0d113 class: Image
Claus Gittinger <cg@exept.de>
parents: 6755
diff changeset
  2113
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2114
defaultPhotometric
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  2115
    "return the default photometric pixel interpretation.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  2116
     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
  2117
     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
  2118
     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
  2119
     - 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
  2120
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2121
    ^ #blackIs0
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2122
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2123
    "Modified: 20.4.1996 / 23:40:41 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2124
    "Created: 10.6.1996 / 18:08:12 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2125
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2126
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2127
imageDepth
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2128
    "return the depth of images represented by instances of
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2129
     this class.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2130
     Must be redefined in concrete subclasses"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2131
2913
c51ac85e9aa2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2891
diff changeset
  2132
    ^ self subclassResponsibility
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2133
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2134
    "Modified: 20.4.1996 / 23:40:41 / cg"
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  2135
!
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  2136
1306
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  2137
imageFileSuffixes
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  2138
    "return a collection of suffixes which are recognized as image-file suffix"
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  2139
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  2140
    ^ MIMETypes imageFileSuffixes
1306
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  2141
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  2142
    "
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  2143
     Image imageFileSuffixes
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  2144
    "
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  2145
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  2146
    "Modified: 30.6.1997 / 22:04:39 / cg"
1306
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  2147
!
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  2148
1783
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2149
imageReaderClassForMIME:mimeType
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2150
    "return an appropriate imageReader class for a given mime type;
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2151
     nil if there is none (or it did not install itself)"
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2152
1801
3dff7fb2bd59 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1800
diff changeset
  2153
    ^ MIMETypes imageReaderForType:mimeType
1783
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2154
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2155
    "
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2156
     Image imageReaderClassForMIME:'image/tiff'
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2157
     Image imageReaderClassForMIME:'image/x-portable-pixmap'
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2158
    "
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2159
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2160
    "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
  2161
    "Modified: 30.6.1997 / 21:54:10 / cg"
1783
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2162
!
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2163
1572
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  2164
imageReaderClassForSuffix:aSuffix
1783
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2165
    "return an appropriate imageReader class for a given file-suffix;
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2166
     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
  2167
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  2168
    ^ MIMETypes imageReaderForSuffix:aSuffix
1572
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  2169
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  2170
    "
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  2171
     Image imageReaderClassForSuffix:'tiff'
1783
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2172
     Image imageReaderClassForSuffix:'foo'
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2173
    "
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2174
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  2175
    "Modified: 30.6.1997 / 22:05:14 / cg"
1572
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  2176
!
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  2177
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  2178
implementorForDepth:depth
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2179
    "return the class, which best implements images of depth"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2180
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2181
    depth == 1 ifTrue:[^ Depth1Image].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2182
    depth == 2 ifTrue:[^ Depth2Image].
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  2183
    depth <= 4 ifTrue:[^ Depth4Image].
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  2184
    depth <= 8 ifTrue:[^ Depth8Image].
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  2185
    depth <= 16 ifTrue:[^ Depth16Image].
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  2186
    depth <= 24 ifTrue:[^ Depth24Image].
1664
42b1af0353c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1662
diff changeset
  2187
    depth <= 32 ifTrue:[^ Depth32Image].
5299
6b1d1dcf5c85 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5237
diff changeset
  2188
    depth <= 48 ifTrue:[^ Depth48Image].
5313
7c40ea0163ee *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
  2189
    depth <= 64 ifTrue:[^ Depth64Image].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2190
    ^ self
1664
42b1af0353c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1662
diff changeset
  2191
42b1af0353c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1662
diff changeset
  2192
    "Modified: 24.4.1997 / 19:04:52 / cg"
1611
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2193
!
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2194
7795
490b3691a124 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7755
diff changeset
  2195
isAbstract
490b3691a124 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7755
diff changeset
  2196
    ^ self == Image
490b3691a124 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7755
diff changeset
  2197
!
490b3691a124 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7755
diff changeset
  2198
1611
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2199
isImageFileSuffix:aSuffix
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2200
    "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
  2201
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2202
     ^ self imageFileSuffixes includes:(aSuffix asLowercase)
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2203
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2204
    "
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2205
     Image isImageFileSuffix:'gif'
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2206
     Image isImageFileSuffix:'xbm'
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2207
     Image isImageFileSuffix:'foo'
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2208
    "
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2209
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2210
    "Created: 18.4.1997 / 14:55:28 / cg"
1786
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2211
!
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2212
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2213
mimeTypeFromSuffix:suffix
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2214
    "search my suffix information for a mime type and
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2215
     return it; return nil if unknown"
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2216
1802
9a3d7c669727 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2217
    ^ MIMETypes mimeTypeForSuffix:suffix
1786
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2218
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2219
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2220
     Image mimeTypeFromSuffix:'gif'
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2221
     Image mimeTypeFromSuffix:'tiff'
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2222
     Image mimeTypeFromSuffix:'foobar'
1786
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2223
    "
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2224
1802
9a3d7c669727 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2225
    "Modified: 1.7.1997 / 00:17:27 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2226
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2227
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  2228
!Image class methodsFor:'screen capture'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2229
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2230
fromScreen
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2231
    "return an image of the full screen.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2232
     WARNING: this temporarily grabs the display
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2233
              it may not work from within a buttonMotion
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2234
              (use #fromScreen:on:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2235
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2236
    |display|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2237
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2238
    display := Screen current.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2239
    ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2240
        fromScreen:(0@0 corner:(display width @ display height))
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2241
        on:display
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2242
        grab:true
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2243
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2244
    "
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2245
     Image fromScreen
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2246
     Image fromScreen inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2247
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2248
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2249
    "Modified: 26.3.1997 / 10:44:55 / cg"
283
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
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2252
fromScreen:aRectangle
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2253
    "return an image of a part of the screen.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2254
     WARNING: this temporarily grabs the display
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2255
              it may not work from within a buttonMotion
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2256
              (use #fromScreen:on:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2257
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2258
    ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2259
        fromScreen:aRectangle
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2260
        on:Screen current
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2261
        grab:true
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2262
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2263
    "
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2264
     Image fromScreen:(0@0 corner:100@100)
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2265
     (Image fromScreen:(0@0 corner:100@100)) inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2266
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2267
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2268
    "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
  2269
!
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2270
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2271
fromScreen:aRectangle on:aDevice
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2272
    "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
  2273
     another display device.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2274
     WARNING: this temporarily grabs the display
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2275
              it may not work from within a buttonMotion
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2276
              (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
  2277
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2278
    ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2279
        fromScreen:aRectangle
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2280
        on:aDevice
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2281
        grab:true
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
     Image fromScreen:(0@0 corner:100@100)
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2285
    "
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2286
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2287
    "get a snapshot of your friends screen ...
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2288
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2289
     |dpy2|
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
     dpy2 := XWorkstation new initializeFor:'idefix:0'.
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2292
     (Image fromScreen:(dpy2 bounds) on:dpy2) inspect
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2293
    "
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2294
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2295
    "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
  2296
!
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2297
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2298
fromScreen:aRectangle on:aDisplay grab:doGrab
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2299
    "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
  2300
     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
  2301
     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
  2302
     shown while the readout is done.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2303
     WARNING: with doGrab true, this temporarily grabs the display
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2304
              and it may not work from within a buttonMotion
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2305
              (use with a false grabArg then)."
7230
71910d55d08c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7227
diff changeset
  2306
71910d55d08c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7227
diff changeset
  2307
    |depth vis img tmpFile util|
71910d55d08c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7227
diff changeset
  2308
71910d55d08c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7227
diff changeset
  2309
    aDisplay supportsScreenReading ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2310
        "/ workaround: look for a helper utility in support/<os>/screenshot
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2311
        "/ currently there is one for osx.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2312
        tmpFile := Filename newTemporary withSuffix:'png'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2313
        util := Smalltalk packageDirectory asFilename / ('../support/',OperatingSystem getSystemType,'/screenshot').
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2314
        util exists ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2315
            OperatingSystem executeCommand:('%1 %2 png %3 %4 %5 %6'
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2316
                                                bindWith:util pathName
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2317
                                                with:tmpFile pathName
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2318
                                                with:aRectangle left
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2319
                                                with:aRectangle top
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2320
                                                with:aRectangle width
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2321
                                                with:aRectangle height).
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  2322
            ^ [
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  2323
                Image fromFile:tmpFile.
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2324
            ] ensure:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2325
                tmpFile remove.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2326
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2327
        ].
7230
71910d55d08c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7227
diff changeset
  2328
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2329
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2330
    depth := aDisplay depth.
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2331
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2332
    "/
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2333
    "/ 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
  2334
    "/ (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
  2335
    "/  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
  2336
    "/
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2337
    vis := aDisplay visualType.
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2338
    (vis == #TrueColor or:[vis == #DirectColor]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2339
        depth > 8 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2340
            depth := 24.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2341
        ]
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2342
    ].
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2343
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  2344
    img := self newForDepth:depth.
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2345
    ^ img fromScreen:aRectangle on:aDisplay grab:doGrab
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2346
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  2347
    "Modified: / 26-01-1998 / 22:23:08 / cg"
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  2348
    "Modified: / 30-01-2017 / 19:49:01 / stefan"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2349
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2350
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2351
fromScreenArea
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2352
    "return an image of a part of the screen;
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2353
     let user specify screen area.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2354
     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
  2355
     Use #fromUser for ST-80 compatibility.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2356
     WARNING: this temporarily grabs the display
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2357
              it may not work from within a buttonMotion
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2358
              (use #fromScreen:on:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2359
2102
7c7d11aa956e care for empty rectangle in Image>>fromScreenArea
Claus Gittinger <cg@exept.de>
parents: 2081
diff changeset
  2360
    |r|
7c7d11aa956e care for empty rectangle in Image>>fromScreenArea
Claus Gittinger <cg@exept.de>
parents: 2081
diff changeset
  2361
2323
bf88727c4dee wait until button is released in #fromUser.
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  2362
    [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
  2363
    r := Rectangle fromUser.
7c7d11aa956e care for empty rectangle in Image>>fromScreenArea
Claus Gittinger <cg@exept.de>
parents: 2081
diff changeset
  2364
    r width == 0 ifTrue:[^ nil].
7c7d11aa956e care for empty rectangle in Image>>fromScreenArea
Claus Gittinger <cg@exept.de>
parents: 2081
diff changeset
  2365
    r height == 0 ifTrue:[^ nil].
7c7d11aa956e care for empty rectangle in Image>>fromScreenArea
Claus Gittinger <cg@exept.de>
parents: 2081
diff changeset
  2366
    ^ self fromScreen:r
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2367
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2368
    "
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2369
     Image fromScreenArea
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2370
     Image fromScreenArea inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2371
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2372
2323
bf88727c4dee wait until button is released in #fromUser.
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  2373
    "Modified: / 10.9.1998 / 15:59:58 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2374
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2375
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2376
fromUser
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2377
    "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
  2378
     Same as fromScreenArea, for ST-80 compatibility.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2379
     WARNING: this temporarily grabs the display
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2380
              it may not work from within a buttonMotion
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2381
              (use #fromScreen:on:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2382
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2383
    ^ self fromScreenArea
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2384
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2385
    "
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2386
     Image fromUser
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2387
     Image fromUser inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2388
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2389
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2390
    "Modified: 26.3.1997 / 10:45:25 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2391
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2392
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2393
fromView:aView
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2394
    "return an image taken from a views contents as currently
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2395
     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
  2396
     as the Display.
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2397
     Notice that for invisible or partial covered views,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2398
     the returned Image is NOT correct.
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2399
     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
  2400
     WARNING: this temporarily grabs the display
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2401
              it may not work from within a buttonMotion
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2402
              (use #fromView:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2403
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2404
    ^ self
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2405
        fromView:aView
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2406
        grab:true
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  2407
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  2408
    "
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2409
     Image fromView:(Launcher allInstances first window topView)
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2410
     Image fromView:(BrowserView allInstances first topView)
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2411
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2412
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2413
    "get a snapshot from whichever view is active:
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2414
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2415
     |active|
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2416
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2417
     active := WindowGroup activeGroup topViews first.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2418
     (Image fromView:active) inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2419
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2420
1043
0688425d02c9 Rename Launcher-->OldLauncher, NewLauncher-->Launcher.
Stefan Vogel <sv@exept.de>
parents: 1041
diff changeset
  2421
    "Modified: 9.9.1996 / 22:41:01 / stefan"
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2422
    "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
  2423
!
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2424
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2425
fromView:aView grab:doGrab
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2426
    "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
  2427
     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
  2428
     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
  2429
     shown while the readout is done.
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2430
     The returned image has the same depth and photometric
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2431
     as the Display.
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2432
     Notice that for invisible or partial covered views,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2433
     the returned Image is NOT correct.
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2434
     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
  2435
     WARNING: with doGrab true, this temporarily grabs the display
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2436
              and it may not work from within a buttonMotion
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2437
              (use with a false grabArg then)."
4540
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2438
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2439
    ^ self fromView:aView grab:doGrab withDecoration:false
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2440
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2441
    "Created: / 26.3.1997 / 10:34:20 / cg"
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2442
    "Modified: / 10.10.2001 / 14:13:29 / cg"
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2443
!
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2444
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2445
fromView:aView grab:doGrab withDecoration:withDecoration
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2446
    "return an image taken from a views contents as currently
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2447
     on the screen, optionally with decoration included.
4540
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2448
     If the doGrab argument is true, the display
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2449
     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
  2450
     shown while the readout is done.
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2451
     The returned image has the same depth and photometric
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2452
     as the Display.
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2453
     Notice that for invisible or partial covered views,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2454
     the returned Image is NOT correct.
4540
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2455
     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
  2456
     WARNING: with doGrab true, this temporarily grabs the display
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2457
              and it may not work from within a buttonMotion
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2458
              (use with a false grabArg then)."
4540
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2459
7271
3d35b4e39ec4 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7242
diff changeset
  2460
    |org ext viewsDevice cH bW bH|
3d35b4e39ec4 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7242
diff changeset
  2461
3d35b4e39ec4 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7242
diff changeset
  2462
    viewsDevice := aView graphicsDevice.
3d35b4e39ec4 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7242
diff changeset
  2463
    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
  2464
    ext := aView extent.
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2465
    withDecoration ifTrue:[
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2466
        viewsDevice isWindowsPlatform ifTrue:[
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2467
            cH := viewsDevice captionHeight.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2468
            bW := (viewsDevice getSystemMetrics: #SM_CXFRAME )
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2469
                  "+ ( device getSystemMetrics: #borderFrameWidth )".
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2470
            bH := (viewsDevice getSystemMetrics: #SM_CYFRAME )
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2471
                  " + ( device getSystemMetrics: #borderFrameHeight )".
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2472
            org := org - (bW @ (bH + cH)).
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2473
            ext := ext + ((bW + bW) @ (bH+bH+cH)).
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  2474
        ].
4540
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2475
    ].
7271
3d35b4e39ec4 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7242
diff changeset
  2476
    ^ 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
  2477
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2478
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2479
     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
  2480
     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
  2481
    "
3518
983e7730a905 use new translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents: 3507
diff changeset
  2482
4574
4b65895bbb6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4565
diff changeset
  2483
    "Created: / 26-03-1997 / 10:34:20 / cg"
4b65895bbb6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4565
diff changeset
  2484
    "Modified: / 08-09-2006 / 15:41:41 / cg"
157
claus
parents: 154
diff changeset
  2485
! !
claus
parents: 154
diff changeset
  2486
3880
c4c8268a2d9f method category rename
Claus Gittinger <cg@exept.de>
parents: 3876
diff changeset
  2487
!Image methodsFor:'Compatibility-Squeak'!
3475
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2488
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2489
boundingBox
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2490
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2491
    ^ self bounds
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2492
!
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2493
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2494
colormapIfNeededForDepth:d
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2495
    ^ nil
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2496
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2497
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2498
!
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2499
6308
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2500
colorsFromArray:anArrayOfRGBTriples
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2501
    "for squeak compatibility with ColorForm:
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2502
     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
  2503
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2504
    |newMap|
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2505
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2506
    newMap := Colormap new:anArrayOfRGBTriples size.
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2507
    anArrayOfRGBTriples doWithIndex:[:rgb :i |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2508
        newMap at:i putRGBTriple:rgb
6308
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2509
    ].
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2510
    self colorMap:newMap.
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2511
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2512
    "
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2513
     Depth8Image new
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2514
        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
  2515
    "
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
3475
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2518
fill:aRectangle fillColor:aColor
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2519
    "fill the rectangular area specified by aRectangle with the given color"
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2520
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2521
    self fillRectangle:aRectangle withColor:aColor
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2522
!
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2523
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2524
fillBlack:aRectangle
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2525
    "fill the rectangular area specified by aRectangle with the black color"
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2526
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2527
    self fillRectangle:aRectangle withColor:Color black
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2528
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2529
    "
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2530
     |img|
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2531
     img := Image extent:100@100 depth:24.
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2532
     img photometric:#rgb.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2533
     img data:(ByteArray new:100*100*3).
3475
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2534
     img fillWhite:(0@0 corner:100@100).
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2535
     img fillBlack:(10@10 corner:90@90).
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2536
     img inspect.
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2537
    "
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2538
!
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
fillWhite:aRectangle
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2541
    "fill the rectangular area specified by aRectangle with the white color"
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
    self fillRectangle:aRectangle withColor:Color white
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2544
!
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2545
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2546
isTransparentAt:aPoint
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2547
    mask isNil ifTrue:[ ^ false].
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2548
    ^ (mask pixelAt:aPoint) == 0
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2549
! !
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2550
3880
c4c8268a2d9f method category rename
Claus Gittinger <cg@exept.de>
parents: 3876
diff changeset
  2551
!Image methodsFor:'Compatibility-VW'!
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2552
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2553
asCachedImage
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2554
    "return the receiver associated to the current screens device.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2555
     For ST-80 compatibility
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2556
     (ST/X uses Image for both device- and nonDevice-images)"
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2557
2832
793500016a2b #on: -> #onDevice:
Claus Gittinger <cg@exept.de>
parents: 2801
diff changeset
  2558
    ^ self onDevice:Screen current
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2559
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2560
    "Modified: 23.4.1996 / 11:10:32 / cg"
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2561
!
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2562
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2563
asRetainedMedium
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2564
    "return the receiver associated to the current screens device.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2565
     For ST-80 compatibility
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2566
     (ST/X uses Image for both device- and nonDevice-images)"
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2567
2832
793500016a2b #on: -> #onDevice:
Claus Gittinger <cg@exept.de>
parents: 2801
diff changeset
  2568
    ^ self onDevice:Screen current
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2569
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2570
    "Modified: 23.4.1996 / 11:10:32 / cg"
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2571
    "Created: 27.1.1997 / 15:49:08 / cg"
1325
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2572
!
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2573
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2574
bounds:newBounds
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2575
    ^ self
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2576
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2577
    "Created: 10.2.1997 / 12:44:46 / cg"
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2578
!
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2579
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2580
containsPoint:aPoint
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2581
    "in st-80, images are visualComponents ..."
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2582
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2583
    ^ self bounds containsPoint:aPoint
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2584
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2585
    "Created: 6.3.1997 / 15:24:12 / cg"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2586
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2587
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2588
convertToPalette:aColormap renderedBy:anImageRenderer
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2589
    "this does not really mimicri the corresponding ST-80 functionality"
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2590
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2591
    |monoBits convertedImage|
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2592
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2593
    aColormap size == 2 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2594
        anImageRenderer class == OrderedDither ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2595
            monoBits := self orderedDitheredMonochromeBits.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2596
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2597
            monoBits := self floydSteinbergDitheredMonochromeBits.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2598
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2599
        (((aColormap at:1) = Color black)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2600
        and:[(aColormap at:2) = Color white]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2601
            "/ ok
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2602
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2603
            (((aColormap at:1) = Color white)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2604
            and:[(aColormap at:2) = Color black]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2605
                monoBits invert
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2606
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2607
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2608
        convertedImage := Depth1Image width:width height:height fromArray:monoBits.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2609
        convertedImage palette:aColormap.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2610
        ^ convertedImage
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2611
    ].
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2612
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2613
    self error:'unimplemented operation'.
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2614
    ^ self
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2615
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2616
    "Modified: 1.3.1997 / 17:25:50 / cg"
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2617
!
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2618
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2619
paintBasis
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2620
    "huh - whats that;
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2621
     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
  2622
     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
  2623
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2624
    ^ ColorValue
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2625
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2626
    "Created: 6.3.1997 / 15:24:19 / cg"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2627
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2628
1325
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2629
preferredBounds
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2630
    ^ self bounds
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2631
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2632
    "Created: 10.2.1997 / 12:42:36 / cg"
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2633
!
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2634
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2635
tile:bounds from:origin in:tile rule:rule
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2636
    |orgX orgY tW tH|
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2637
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2638
    origin ~= (0@0) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2639
        self shouldImplement.
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2640
    ].
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2641
    bounds ~= self bounds ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2642
        self shouldImplement.
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2643
    ].
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2644
    rule ~= #over ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2645
        self shouldImplement.
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
    orgX := origin x.
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2649
    orgY := origin y.
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2650
    tW := tile width.
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2651
    tH := tile height.
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2652
    (bounds top) to:(bounds bottom) by:tH do:[:dstY |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2653
        (bounds left) to:(bounds right) by:(tile width) do:[:dstX |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2654
            self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2655
                copyFrom:tile
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2656
                x:orgX y:orgY
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2657
                toX:dstX y:dstY
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2658
                width:tW height:tH.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2659
        ].
4380
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
!
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2662
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2663
valueAtPoint:aPoint put:aColorValue
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2664
    aColorValue isInteger ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2665
        self colorAtX:aPoint x y:aPoint y put:aColorValue
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2666
    ] ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2667
        self pixelAtX:aPoint x y:aPoint y put:aColorValue
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2668
    ]
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2669
! !
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2670
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2671
!Image methodsFor:'accessing'!
48194c26a46c Initial revision
claus
parents:
diff changeset
  2672
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2673
bitsPerSample
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2674
    "return the number of bits per sample.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2675
     The return value is an array of bits-per-plane."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2676
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2677
    bitsPerSample notNil ifTrue:[^ bitsPerSample].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2678
    ^ Array with:self depth
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2679
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2680
    "Modified: 10.6.1996 / 18:04:21 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2681
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2682
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2683
colorMap
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2684
    "return the colormap"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2685
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2686
    ^ colorMap
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2687
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2688
7834
329ce8391689 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7824
diff changeset
  2689
colorMap:newColorMap
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2690
    "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
  2691
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  2692
    |oldSize "{ Class: SmallInteger }"
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2693
     sameColors|
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2694
7834
329ce8391689 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7824
diff changeset
  2695
    (newColorMap isNil and:[colorMap isNil]) ifTrue:[^ self].
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2696
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2697
    sameColors := false.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2698
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2699
    photometric == #palette ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2700
        "/ any change at all ?
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  2701
        oldSize := colorMap size.
7834
329ce8391689 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7824
diff changeset
  2702
        newColorMap size >= oldSize ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2703
            sameColors := true.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2704
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2705
            1 to:oldSize do:[:idx |
7834
329ce8391689 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7824
diff changeset
  2706
                (newColorMap at:idx) = (colorMap at:idx) ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2707
                    sameColors := false.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2708
                ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2709
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2710
        ].
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2711
    ].
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2712
7834
329ce8391689 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7824
diff changeset
  2713
    self setColorMap:newColorMap.
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2714
    sameColors ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2715
        ^ self
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2716
    ].
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2717
7834
329ce8391689 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7824
diff changeset
  2718
    newColorMap notNil ifTrue:[
329ce8391689 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7824
diff changeset
  2719
        newColorMap isFixedPalette ifTrue:[
329ce8391689 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7824
diff changeset
  2720
            photometric := #rgb
329ce8391689 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7824
diff changeset
  2721
        ] ifFalse:[  
329ce8391689 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7824
diff changeset
  2722
            self assert:(self depth <= 8).
329ce8391689 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7824
diff changeset
  2723
            photometric := #palette.
329ce8391689 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7824
diff changeset
  2724
        ].
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  2725
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2726
        (photometric == #palette) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2727
            photometric := #blackIs0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2728
        ]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  2729
    ].
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2730
    deviceForm notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2731
        self release
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2732
    ]
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2733
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  2734
    "Modified: / 31-08-1995 / 03:05:59 / claus"
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  2735
    "Modified: / 31-01-2017 / 14:48:56 / stefan"
7834
329ce8391689 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7824
diff changeset
  2736
    "Modified: / 03-02-2017 / 16:52:33 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2737
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2738
2068
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
  2739
colorMapFromArray: anArray
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2740
    "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
  2741
     The (byte-)Array argument should be of the form:
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2742
        #( 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
  2743
     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
  2744
3876
f4dc6267a30a getting rid of colorMap
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  2745
    self colorMap:(MappedPalette rgbBytesVector:anArray)
3864
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
  2746
!
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
  2747
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
  2748
colorMapFromRGBValueArray:anArray
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2749
    "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
  2750
     The (integer-)Array argument should be of the form:
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2751
        #( rgb0 rgb1  ... rgbN)
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2752
     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
  2753
3876
f4dc6267a30a getting rid of colorMap
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  2754
    self colorMap:(MappedPalette rgbValueVector:anArray)
2068
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
  2755
!
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
  2756
757
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2757
container:aVisualContainer
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2758
    "ignored here - added to allow images to be used like
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2759
     VisualComponents (later, Image should inherit from it)"
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2760
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2761
    "Created: 28.5.1996 / 23:43:49 / cg"
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2762
    "Modified: 29.5.1996 / 10:22:23 / cg"
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2763
!
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2764
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2765
depth
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2766
    "return the depth of the image"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2767
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2768
    ^ self bitsPerPixel
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2769
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2770
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2771
device
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2772
    "return the device, the receiver is associated with.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2773
     Return nil, if the image is unassigned."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2774
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2775
    ^ device
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2776
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2777
7637
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  2778
drawableId
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  2779
    "return the id of the image on the device.
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  2780
     Return nil, if the image is unassigned."
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  2781
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  2782
    deviceForm isNil ifTrue:[^ nil].
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  2783
    ^ deviceForm drawableId
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  2784
!
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  2785
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2786
extent
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2787
    "return the images extent"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2788
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2789
    ^ width@height
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2790
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2791
1950
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2792
fileName
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2793
    "return the value of the instance variable 'fileName' (automatically generated)"
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2794
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2795
    ^ fileName
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2796
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2797
    "Created: / 3.11.1997 / 14:54:46 / cg"
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2798
!
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2799
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2800
fileName:something
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2801
    "set the value of the instance variable 'fileName' (automatically generated)"
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2802
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2803
    fileName := something.
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2804
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2805
    "Created: / 3.11.1997 / 14:54:46 / cg"
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2806
!
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2807
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2808
fullColorId
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2809
    "return the id of the full color image on the device.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2810
     Return nil, if the image is unassigned."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2811
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2812
    fullColorDeviceForm isNil ifTrue:[^ nil].
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2813
    ^ fullColorDeviceForm id
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2814
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2815
728
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  2816
graphicsDevice
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  2817
    "same as #device - for ST-80 compatibility"
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  2818
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  2819
    ^ device
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  2820
!
744
db883c9b74b8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 728
diff changeset
  2821
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2822
height
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2823
    "return the height of the image"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2824
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2825
    ^ height
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2826
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2827
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2828
id
7637
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
  2829
    ^ self drawableId  
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2830
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2831
2081
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2832
imageSequence
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2833
    "return the frameSequence of which this image is a part of;
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2834
     nil if it is not part of a sequence."
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2835
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2836
    ^ imageSequence
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2837
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2838
    "Created: / 1.4.1998 / 14:43:00 / cg"
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2839
!
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2840
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2841
imageSequence:aCollection
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2842
    "private entry for imageReaders - set the frameSequence of which
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2843
     this image is a part of"
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2844
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2845
    imageSequence := aCollection
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2846
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2847
    "Created: / 1.4.1998 / 14:42:36 / cg"
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2848
!
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2849
896
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2850
mask
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2851
    ^ mask
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2852
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2853
    "Created: 21.6.1996 / 12:57:44 / cg"
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2854
!
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2855
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2856
mask:anotherImage
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2857
    "set the images mask - currently, this may be nil or a Depth1Image.
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2858
     (it is planned to support alpha information in a Depth8 maskImage in
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2859
      the near future).
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2860
     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
  2861
                       1-bit is present in the mask will be drawn;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2862
                       0-bit mask pixels lead to transparent pixels.
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2863
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2864
     For depth8 masks: (future):
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2865
                       each pixel specifies the alpha value (0..255),
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2866
                       which specifies the transparency of that pixel.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2867
                       0 means completely transparent, 255 means completely
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2868
                       opaque. The 1-plane mask is a special case of this,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  2869
                       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
  2870
                       alpha value of 255."
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2871
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2872
    mask := anotherImage.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2873
    maskedPixelsAre0 := false.
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2874
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2875
    "Created: 27.6.1996 / 17:45:22 / cg"
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2876
    "Modified: 12.4.1997 / 12:04:39 / cg"
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2877
!
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2878
1587
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2879
maskedPixelsAre0
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2880
    "return true if masked pixels have been cleared to zero"
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2881
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2882
    ^ maskedPixelsAre0 == true
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2883
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2884
    "Modified: / 22.8.1998 / 11:27:22 / cg"
1587
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2885
!
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2886
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2887
maskedPixelsAre0:aBoolean
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2888
    "set/clear the flag which states if masked pixels
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2889
     have been set to zero. Knowing this to be true allows
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2890
     faster drawing of the image later; (however, not setting
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2891
     it will still produce correct output).
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2892
     This flag is typically set by image readers."
1587
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2893
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2894
    maskedPixelsAre0 := aBoolean
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2895
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2896
    "Modified: 12.4.1997 / 12:08:42 / cg"
1587
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2897
!
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2898
7374
b1a4e6ba38cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7373
diff changeset
  2899
metaData
b1a4e6ba38cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7373
diff changeset
  2900
    ^ metaData
b1a4e6ba38cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7373
diff changeset
  2901
!
b1a4e6ba38cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7373
diff changeset
  2902
b1a4e6ba38cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7373
diff changeset
  2903
metaData:something
b1a4e6ba38cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7373
diff changeset
  2904
    metaData := something.
b1a4e6ba38cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7373
diff changeset
  2905
!
b1a4e6ba38cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7373
diff changeset
  2906
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2907
monochromeId
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2908
    "return the id of the monochrome image on the device.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2909
     Return nil, if the image is unassigned."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2910
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2911
    monoDeviceForm isNil ifTrue:[^ nil].
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2912
    ^ monoDeviceForm id
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2913
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2914
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2915
palette
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2916
    "return the colormap; ST-80 compatibility"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2917
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2918
    ^ colorMap
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2919
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2920
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2921
palette:aColormap
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2922
    "set the colormap; ST-80 compatibility"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2923
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  2924
    self colorMap:aColormap
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2925
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2926
    "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
  2927
    "Modified: 8.6.1996 / 09:54:02 / cg"
592
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
photometric
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  2931
    "return the photometric, a symbol such as #palette, #rgb etc.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  2932
     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
  2933
     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
  2934
     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
  2935
     - 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
  2936
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2937
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2938
    ^ photometric
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2939
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2940
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2941
samplesPerPixel
6840
3dee5e952e94 class: Image
Stefan Vogel <sv@exept.de>
parents: 6831
diff changeset
  2942
    "return the number of samples per pixel in the image."
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2943
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2944
    samplesPerPixel notNil ifTrue:[^ samplesPerPixel].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2945
    ^ 1
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2946
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2947
    "Modified: 10.6.1996 / 18:03:30 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2948
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2949
7834
329ce8391689 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7824
diff changeset
  2950
setColorMap:newColorMap
329ce8391689 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7824
diff changeset
  2951
    newColorMap isColormap ifTrue:[
329ce8391689 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7824
diff changeset
  2952
        colorMap := newColorMap.
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  2953
    ] ifFalse:[
7834
329ce8391689 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7824
diff changeset
  2954
        colorMap := MappedPalette withColors:newColorMap.
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  2955
    ].
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  2956
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  2957
    "Modified: / 30-01-2017 / 19:15:34 / stefan"
7834
329ce8391689 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7824
diff changeset
  2958
    "Modified (format): / 03-02-2017 / 16:39:48 / cg"
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2959
!
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2960
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2961
width
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2962
    "return the width of the image"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2963
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2964
    ^ width
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2965
! !
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2966
3263
bd92a12c9316 category changes
Claus Gittinger <cg@exept.de>
parents: 3259
diff changeset
  2967
!Image methodsFor:'accessing-pixels'!
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2968
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2969
at:aPoint
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2970
    "WARNING: for now, this returns a pixels color
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2971
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2972
     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
  2973
     Use #colorAt: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2974
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2975
     retrieve the pixel at aPoint; return a color.
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2976
     Pixels start at 0@0 for upper left pixel, end at
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2977
     (width-1)@(height-1) for lower right pixel.
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2978
     You should not use this method for image-processing, its
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2979
     very slow ...
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2980
     (it is meant to access individual pixels - for example, in a bitmap editor)"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2981
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  2982
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  2983
7482
0e29bd25788b #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 7481
diff changeset
  2984
    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
  2985
    ^ self colorAtX:(aPoint x) y:(aPoint y)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2986
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
  2987
    "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
  2988
    "Modified: / 9.1.1998 / 20:33:52 / stefan"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2989
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  2990
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2991
at:aPoint put:aColor
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2992
    "WARNING: for now, this expects a pixels color
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2993
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2994
     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
  2995
     Use #colorAt:put: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2996
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2997
     set the pixel at aPoint to aColor.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2998
     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
  2999
     (width-1)@(height-1) for lower right pixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3000
     You should not use this method for image-processing, its
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3001
     very slow ...
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3002
     (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
  3003
7482
0e29bd25788b #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 7481
diff changeset
  3004
    aColor isInteger ifTrue:[
0e29bd25788b #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 7481
diff changeset
  3005
        ^ self pixelAtX:aPoint x y:aPoint y put:aColor.
0e29bd25788b #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 7481
diff changeset
  3006
    ].
0e29bd25788b #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 7481
diff changeset
  3007
    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
  3008
    ^ self colorAtX:aPoint x y:aPoint y put:aColor.
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  3009
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
  3010
    "Modified: / 21.6.1997 / 13:16:02 / cg"
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
  3011
    "Modified: / 9.1.1998 / 20:34:15 / stefan"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3012
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3013
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3014
atImageAndMask:aPoint put:aColorOrPixelOrNil
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  3015
    "set the pixel at x/y to aColor.
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3016
     If aColor is a mask color (i.e. Color noColor) the mask pixel will be set to 0 (transparent),
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3017
     otherwise to 1. Nil is treated like noColor.
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  3018
     (used by the bitmap editor)"
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  3019
2523
4c197af8cc50 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2502
diff changeset
  3020
    |maskVal|
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3021
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3022
    (aColorOrPixelOrNil notNil and:[aColorOrPixelOrNil ~= Color noColor]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3023
        maskVal := 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3024
        aColorOrPixelOrNil isInteger ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3025
            self pixelAt:aPoint put:aColorOrPixelOrNil.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3026
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3027
            self colorAt:aPoint put:aColorOrPixelOrNil
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3028
        ]
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3029
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3030
        maskVal := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3031
        self pixelAt:aPoint put:0.
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3032
    ].
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3033
    mask notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3034
        mask pixelAt:aPoint put:maskVal
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3035
    ].
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3036
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3037
    "Modified: / 30.9.1998 / 22:42:44 / cg"
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3038
!
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3039
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3040
atImageAndMask:aPoint putValue:aPixelValueOrNil
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3041
    "set the pixel at x/y to aColor.
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3042
     If aPixelValueOrNil is nil, the mask pixel will be set to 0 (transparent),
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  3043
     otherwise to 1. (used by the bitmap editor)"
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3044
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3045
    |pixVal maskVal|
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3046
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3047
    aPixelValueOrNil notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3048
        pixVal := aPixelValueOrNil.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3049
        maskVal := 1.
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3050
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3051
        pixVal := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3052
        maskVal := 0.
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3053
    ].
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3054
    mask notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3055
        mask pixelAt:aPoint put:maskVal
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3056
    ].
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3057
    self pixelAt:aPoint put:pixVal
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3058
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3059
    "Modified: / 30.9.1998 / 22:42:44 / cg"
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  3060
!
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  3061
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3062
atPoint:aPoint
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3063
    "ST-80 compatibility: return the pixelValue at:aPoint."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3064
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3065
    ^ self pixelAtX:aPoint x y:aPoint y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3066
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3067
    "Modified: 24.4.1997 / 16:18:44 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3068
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3069
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3070
atPoint:aPoint put:aPixelValue
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3071
    "ST-80 compatibility: set the pixelValue at:aPoint."
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3072
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3073
    ^ self pixelAtX:aPoint x y:aPoint y put:aPixelValue
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3074
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3075
    "Modified: 24.4.1997 / 17:17:59 / cg"
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3076
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3077
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3078
atX:x y:y
7482
0e29bd25788b #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 7481
diff changeset
  3079
    <resource: #obsolete>
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3080
    "WARNING: for now, this returns a pixels color
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3081
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3082
     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
  3083
     Use #colorAt: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3084
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3085
     Retrieve a pixel at x/y; return a color.
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3086
     Pixels start at 0@0 for upper left pixel, end at
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3087
     (width-1)@(height-1) for lower right pixel.
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3088
     You should not use this method for image-processing, its
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3089
     very slow ...
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3090
     (it is meant to access individual pixels - for example, in a bitmap editor)"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3091
7482
0e29bd25788b #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 7481
diff changeset
  3092
    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
  3093
    ^ self colorAtX:x y:y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3094
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  3095
    "Modified: 21.6.1997 / 13:10:32 / cg"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3096
!
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3097
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3098
atX:x y:y put:aColor
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3099
    "WARNING: for now, this expects a pixels color
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3100
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3101
     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
  3102
     Use #colorAt:put: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3103
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3104
     set the pixel at x/y to aColor.
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3105
     Pixels start at 0@0 for the upper left pixel, end at
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3106
     (width-1)@(height-1) for the lower right pixel.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  3107
     This method checks if the color can be stored in the image.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  3108
     (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
  3109
     You should not use this method for image-processing, it is very slow ...
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3110
     (it is meant to access individual pixels - for example, in a bitmap editor)"
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3111
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  3112
    aColor isInteger ifTrue:[
7482
0e29bd25788b #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 7481
diff changeset
  3113
        ^ self pixelAtX:x y:y put:aColor
0e29bd25788b #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 7481
diff changeset
  3114
    ].
0e29bd25788b #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 7481
diff changeset
  3115
    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
  3116
    ^ self colorAtX:x y:y put:aColor
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3117
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  3118
    "Modified: 21.6.1997 / 13:10:44 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3119
!
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3120
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3121
atX:x y:y putValue:aPixelValue
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3122
    "set the pixel at x/y to aPixelValue.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3123
     The interpretation of the pixelValue depends on the photometric
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3124
     and the colormap. (see also: Image>>atX:y:put:)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3125
     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
  3126
     (width-1) @ (height-1) for the lower right pixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3127
     You should not use this method for image-processing, its
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3128
     very slow ...
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3129
     (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
  3130
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  3131
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  3132
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3133
    self obsoleteMethodWarning:'use #pixelAtX:y:put:'.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3134
    ^ self pixelAtX:x y:y put:aPixelValue.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3135
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3136
    "Modified: 24.4.1997 / 17:15:45 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3137
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3138
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3139
bits
7373
61933c223183 added metaData instVar (for free use by image reader)
Claus Gittinger <cg@exept.de>
parents: 7363
diff changeset
  3140
    "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
  3141
     depending on the photometric, this has to be interpreted as monochrome,
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3142
     greyscale, palette or rgb data.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3143
     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
  3144
     will store 2 pixels per byte, whereas a 2-bitPerPixel image will store
be0fa075e4c4 comment
Claus Gittinger <cg@exept.de>
parents: 4414
diff changeset
  3145
     4 pixels per byte."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3146
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3147
    bytes isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3148
        pixelFunction notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3149
            self createPixelStore.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3150
            0 to:height-1 do:[:y |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3151
                0 to:width-1 do:[:x |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3152
                    self pixelAtX:x y:y put:(pixelFunction value:x value:y)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3153
                ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3154
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3155
        ].
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3156
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3157
    ^ bytes
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3158
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3159
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3160
colAt:x into:aPixelBuffer
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3161
    "fill aBuffer with pixel values retrieved from a single column.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3162
     (eg. a vertical span)    
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3163
     Notice: row/column coordinates start at 0."
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3164
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3165
    ^ self colAt:x into:aPixelBuffer startingAt:1
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3166
!
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3167
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3168
colAt:x into:aPixelBuffer startingAt:startIndex
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3169
    "fill aBuffer with pixel values retrieved from a single column.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3170
     (eg. a vertical span)    
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3171
     Notice: row/column coordinates start at 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3172
     This is a slow fallBack method, which works with any depth;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3173
     concrete image subclasses should redefine this for more performance."
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3174
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3175
    |h "{ Class: SmallInteger }"|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3176
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3177
    h := height-1.    
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3178
    0 to:h do:[:row |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3179
        aPixelBuffer at:(row + startIndex) put:(self pixelAtX:x y:row)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3180
    ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3181
!
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3182
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3183
colAt:x putAll:pixelArray
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3184
    "store a single column's pixels from bits in the argument;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3185
     (eg. a vertical span)    
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3186
     Notice: row/column coordinates start at 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3187
     This is a slow fallBack method, which works with any depth;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3188
     concrete image subclasses should redefine this for more performance."
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3189
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3190
    ^ self colAt:x putAll:pixelArray startingAt:1
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3191
!
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3192
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3193
colAt:x putAll:pixelArray startingAt:startIndex
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3194
    "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
  3195
     (eg. a vertical span)    
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3196
     Notice: row/column coordinates start at 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3197
     This is a slow fallBack method, which works with any depth;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3198
     concrete image subclasses should redefine this for more performance."
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3199
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3200
    |h "{ Class: SmallInteger }"|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3201
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3202
    h := height-1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3203
    0 to:h do:[:row |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3204
        self pixelAtX:x y:row put:(pixelArray at:(row + startIndex))
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3205
    ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3206
    ^ pixelArray
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3207
!
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3208
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3209
colorAt:aPoint
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3210
    "retrieve a pixel at x/y; return a color.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3211
     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
  3212
     (width-1)@(height-1) for lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3213
     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
  3214
     very slow ...
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3215
     (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
  3216
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3217
    ^ self colorAtX:(aPoint x) y:(aPoint y)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3218
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3219
    "Created: 24.4.1997 / 17:02:31 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3220
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3221
1962
8c7377d243f6 save mask in storeOn.
tz
parents: 1950
diff changeset
  3222
colorAt: aPoint put:aColor
8c7377d243f6 save mask in storeOn.
tz
parents: 1950
diff changeset
  3223
8c7377d243f6 save mask in storeOn.
tz
parents: 1950
diff changeset
  3224
    self colorAtX: aPoint x y: aPoint y put:aColor
8c7377d243f6 save mask in storeOn.
tz
parents: 1950
diff changeset
  3225
!
8c7377d243f6 save mask in storeOn.
tz
parents: 1950
diff changeset
  3226
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3227
colorAtX:x y:y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3228
    "retrieve a pixel at x/y; return a color.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3229
     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
  3230
     (width-1)@(height-1) for lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3231
     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
  3232
     very slow ...
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3233
     (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
  3234
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3235
    |pixel|
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
    pixel := self pixelAtX:x y:y.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3238
    ^ self colorFromValue:pixel
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3239
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3240
    "Modified: 24.4.1997 / 16:18:53 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3241
    "Created: 24.4.1997 / 17:00:52 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3242
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3243
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3244
colorAtX:x y:y put:aColor
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3245
    "set the pixel at x/y to aColor.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3246
     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
  3247
     (width-1)@(height-1) for the lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3248
     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
  3249
     (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
  3250
     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
  3251
     (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
  3252
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3253
    |pixel|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3254
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3255
    pixel := self valueFromColor:aColor.
2182
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3256
    pixel isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3257
        ^ UnrepresentableColorSignal raiseErrorString:'cannot store color - not in colormap'.
2182
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3258
    ].
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3259
    self pixelAtX:x y:y put:pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3260
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3261
    "Modified: 24.4.1997 / 17:36:20 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3262
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3263
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3264
data
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3265
    "for backward compatibility - will vanish"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3266
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  3267
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  3268
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3269
    self obsoleteMethodWarning:'use #bits'.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3270
    ^ self bits
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3271
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3272
    "Modified: 24.4.1997 / 17:37:57 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3273
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3274
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3275
data:aByteArray
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3276
    "for backward compatibility - will vanish"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3277
4175
a9e65365e590 Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 4173
diff changeset
  3278
    <resource:#obsolete>
3966
950a2db201c7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3964
diff changeset
  3279
    self obsoleteMethodWarning:'use #bits:'.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3280
    self bits:aByteArray
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3281
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3282
    "Modified: 24.4.1997 / 17:38:18 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3283
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3284
2182
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3285
maskAt:aPoint
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3286
    "retrieve the maskValue at aPoint - an integer number which is
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3287
     0 for masked pixels (invisible), 1 for unmasked (visible).
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3288
     For images without mask, 1 is returned for all pixels."
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3289
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3290
    ^ self maskAtX:aPoint x y:aPoint y
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3291
!
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3292
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3293
maskAt:aPoint put:maskValue
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3294
    "set the maskValue at aPoint - an integer number which is
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3295
     0 for masked pixels (invisible), 1 for unmasked (visible)."
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3296
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3297
    ^ self maskAtX:aPoint x y:aPoint y put:maskValue
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3298
!
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3299
2182
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3300
maskAtX:x y:y
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3301
    "retrieve the maskValue at aPoint - an integer number which is
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3302
     0 for masked pixels (invisible), 1 for unmasked (visible).
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3303
     For images without mask, 1 is returned for all pixels."
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3304
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3305
    mask isNil ifTrue:[^ 1].
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3306
    ^ mask pixelAtX:x y:y
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3307
!
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3308
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3309
maskAtX:x y:y put:maskValue
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3310
    "set the maskValue at aPoint - an integer number which is
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3311
     0 for masked pixels (invisible), 1 for unmasked (visible)."
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3312
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3313
    mask isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3314
        maskValue == 1 ifTrue:[^ self].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3315
        self error:'image has no mask'.
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3316
    ].
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3317
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3318
    ^ mask pixelAtX:x y:y put:maskValue
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3319
!
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3320
2205
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3321
pixelAt:aPoint
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3322
    "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
  3323
     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
  3324
     (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
  3325
     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
  3326
     very slow ...
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3327
     (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
  3328
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3329
    ^ 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
  3330
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3331
    "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
  3332
!
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3333
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3334
pixelAt:aPoint put:aPixelValue
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3335
    "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
  3336
     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
  3337
     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
  3338
     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
  3339
     (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
  3340
     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
  3341
     very slow ...
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3342
     (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
  3343
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3344
    ^ 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
  3345
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3346
    "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
  3347
!
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3348
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3349
pixelAtX:x y:y
7519
c0603c8183dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7511
diff changeset
  3350
    "retrieve the pixelValue at aPoint; return a pixel (an integer number).
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3351
     Pixels start at 0/0 for upper left pixel, and end at
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3352
     width-1@height-1 for lower right pixel.
7519
c0603c8183dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7511
diff changeset
  3353
     The returned number's interpretation depends on the photometric
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3354
     and the colormap. (see also Image>>at: and Image>>atX:y:)
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3355
     You should not use this method for image-processing of
7519
c0603c8183dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7511
diff changeset
  3356
     big images, it's very slow ...
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3357
     (it is meant to access individual pixels - for example, in a bitmap editor)"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3358
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3359
    pixelFunction notNil ifTrue:[^ pixelFunction value:x value:y].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3360
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3361
    ^ self subclassResponsibility
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3362
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3363
    "Created: 24.4.1997 / 16:06:56 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3364
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3365
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3366
pixelAtX:x y:y put:aPixelValue
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3367
    "set the pixel at x/y to aPixelValue.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3368
     The interpretation of the pixelValue depends on the photometric
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3369
     and the colormap. (see also: Image>>atX:y:put:)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3370
     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
  3371
     (width-1) @ (height-1) for the lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3372
     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
  3373
     very slow ...
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3374
     (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
  3375
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3376
    ^ self subclassResponsibility
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3377
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3378
    "Created: 24.4.1997 / 17:05:11 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3379
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3380
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3381
rgbValueAt:aPoint
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3382
    "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
  3383
     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
  3384
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3385
    ^ self rgbValueAtX:(aPoint x) y:(aPoint y)
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3386
!
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3387
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3388
rgbValueAtX:x y:y
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3389
    "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
  3390
     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
  3391
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3392
    |pixel|
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3393
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3394
    pixel := self pixelAtX:x y:y.
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3395
    ^ self rgbFromValue:pixel
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3396
!
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3397
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  3398
rgbValueAtX:x y:y put:newRGBValue
4858
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3399
    |value|
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3400
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3401
    value := self valueFromRGB:newRGBValue.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3402
    self pixelAtX:x y:y put:value.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3403
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3404
    "Created: / 15-01-2008 / 15:56:10 / cg"
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3405
!
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3406
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3407
rowAt:y
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3408
    "retrieve an array filled with pixel values from a single row.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3409
     (eg. a horizontal span)    
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3410
     Notice: row/column coordinates start at 0.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3411
     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
  3412
     concrete image subclasses should redefine this for more performance."
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3413
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3414
    |pixelArray|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3415
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3416
    pixelArray := self pixelArraySpecies new:width.
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3417
    self rowAt:y into:pixelArray startingAt:1.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3418
    ^ pixelArray
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3419
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3420
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3421
     |i|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3422
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3423
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3424
     (i rowAt:0) inspect
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3425
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3426
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3427
     |i|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3428
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  3429
     i := Image fromFile:'libtool/bitmaps/SBrowser.xbm'.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3430
     (i rowAt:0) inspect
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3431
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3432
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3433
    "Modified: 24.4.1997 / 15:51:24 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3434
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3435
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3436
rowAt:y into:aPixelBuffer
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3437
    "fill aBuffer with pixel values retrieved from a single row.
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3438
     (eg. a horizontal span)    
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3439
     Notice: row/column coordinates start at 0."
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3440
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3441
    ^ self rowAt:y into:aPixelBuffer startingAt:1
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3442
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3443
    "Created: 24.4.1997 / 15:44:46 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3444
    "Modified: 24.4.1997 / 15:51:35 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3445
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3446
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3447
rowAt:y into:aPixelBuffer startingAt:startIndex
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3448
    "fill aBuffer with pixel values retrieved from a single row.
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3449
     (eg. a horizontal span)    
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3450
     Notice: row/column coordinates start at 0.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3451
     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
  3452
     concrete image subclasses should redefine this for more performance."
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3453
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3454
    |w "{ Class: SmallInteger }"|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3455
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3456
    w := width-1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3457
    0 to:w do:[:col |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3458
        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
  3459
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3460
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3461
    "Created: 24.4.1997 / 15:05:21 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3462
    "Modified: 24.4.1997 / 16:52:43 / cg"
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
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3465
rowAt:y putAll:pixelArray
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3466
    "store a single row's pixels from bits in the argument;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3467
     (eg. a horizontal span)    
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3468
     Notice: row/column coordinates start at 0.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3469
     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
  3470
     concrete image subclasses should redefine this for more performance."
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3471
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3472
    ^ self rowAt:y putAll:pixelArray startingAt:1
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3473
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3474
    "Modified: 24.4.1997 / 15:51:58 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3475
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3476
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3477
rowAt:y putAll:pixelArray startingAt:startIndex
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3478
    "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
  3479
     (eg. a horizontal span)    
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3480
     Notice: row/column coordinates start at 0.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3481
     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
  3482
     concrete image subclasses should redefine this for more performance."
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3483
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3484
    |w "{ Class: SmallInteger }"|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3485
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3486
    w := width-1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3487
    0 to:w do:[:col |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3488
        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
  3489
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3490
    ^ pixelArray
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3491
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3492
    "Modified: 24.4.1997 / 17:05:57 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3493
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3494
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3495
valueAt:aPoint
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3496
    "WARNING: for now, this returns a pixels value
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3497
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3498
     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
  3499
     Use #pixelAt: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3500
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3501
     Retrieve the pixelValue at aPoint; return an integer number.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3502
     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
  3503
     width-1@height-1 for lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3504
     The returned numbers interpretation depends on the photometric
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3505
     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
  3506
     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
  3507
     very slow ...
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3508
     (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
  3509
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  3510
    '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
  3511
    ^ self pixelAtX:aPoint x y:aPoint y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3512
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  3513
    "Modified: 21.6.1997 / 13:11:19 / cg"
1660
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
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3516
valueAtX:x y:y
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3517
    "WARNING: for now, this returns a pixels value
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3518
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3519
     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
  3520
     Use #pixelAt: - for future compatibility.
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
     Retrieve the pixelValue at aPoint; return an integer number.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3523
     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
  3524
     width-1@height-1 for lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3525
     The returned numbers interpretation depends on the photometric
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3526
     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
  3527
     You should not use this method for image-processing of
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3528
     big images, its very slow ...
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3529
     (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
  3530
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  3531
    '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
  3532
    ^ self pixelAtX:x y:y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3533
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  3534
    "Modified: 21.6.1997 / 13:11:29 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3535
! !
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3536
3263
bd92a12c9316 category changes
Claus Gittinger <cg@exept.de>
parents: 3259
diff changeset
  3537
!Image methodsFor:'accessing-private'!
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3538
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3539
bits:aByteArray
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3540
    "set the raw data.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3541
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3542
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3543
     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
  3544
     existing image may confuse later pixel interpretation
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3545
     (it does not care for colormaps and/or cached device image flushing)."
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3546
6894
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3547
    |expectedSize d|
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3548
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3549
    bytes := aByteArray.
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3550
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3551
    "/ sanity check:
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3552
    "/ there seem to be images in some image-resource methods,
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3553
    "/ which were written with an invalid packed pixel string.
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3554
    "/ 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
  3555
    "/ If you encounter this halt,
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3556
    "/ 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
  3557
6894
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3558
    (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
  3559
        (d <= 8) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3560
            expectedSize := (self bytesPerRow * height).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3561
            bytes size < expectedSize ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3562
                Smalltalk isSmalltalkDevelopmentSystem ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3563
                    self breakPoint:#cg info:'invalid bytearray size'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3564
                ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3565
                bytes := (ByteArray new:expectedSize) replaceFrom:1 with:bytes; yourself.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3566
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3567
        ].
6894
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3568
    ].
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3569
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3570
    "Modified: 23.4.1996 / 11:08:28 / cg"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3571
!
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3572
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3573
bits:aByteArrayArg colorMap:clrMapArg
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3574
    "set the raw data.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3575
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3576
     This interface is only to be used when initializing
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3577
     instances or by image readers. Calling for a change of an
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3578
     existing image may confuse later pixel interpretation
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3579
     (it does not care for colormaps and/or cached device image flushing)."
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3580
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3581
    self bits:aByteArrayArg.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3582
    self colorMap:clrMapArg.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3583
!
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3584
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3585
bits:aByteArrayArg colorMap:clrMapArg mask:maskArg
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3586
    "set the raw data.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3587
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3588
     This interface is only to be used when initializing
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3589
     instances or by image readers. Calling for a change of an
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3590
     existing image may confuse later pixel interpretation
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3591
     (it does not care for colormaps and/or cached device image flushing)."
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3592
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3593
    self bits:aByteArrayArg.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3594
    self colorMap:clrMapArg.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3595
    self mask:maskArg
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3596
!
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3597
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3598
bits:aByteArrayArg colorMapFromArray:clrMapArg
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3599
    "set the raw data.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3600
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3601
     This interface is only to be used when initializing
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3602
     instances or by image readers. Calling for a change of an
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3603
     existing image may confuse later pixel interpretation
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3604
     (it does not care for colormaps and/or cached device image flushing)."
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3605
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3606
    self bits:aByteArrayArg.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3607
    self colorMapFromArray:clrMapArg.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3608
!
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3609
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3610
bits:aByteArrayArg colorMapFromArray:clrMapArg mask:maskArg
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3611
    "set the raw data.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3612
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3613
     This interface is only to be used when initializing
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3614
     instances or by image readers. Calling for a change of an
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3615
     existing image may confuse later pixel interpretation
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3616
     (it does not care for colormaps and/or cached device image flushing)."
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3617
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3618
    self bits:aByteArrayArg.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3619
    self colorMapFromArray:clrMapArg.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3620
    self mask:maskArg
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3621
!
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3622
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3623
bits:aByteArrayArg mask:maskArg
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3624
    "set the raw data.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3625
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3626
     This interface is only to be used when initializing
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3627
     instances or by image readers. Calling for a change of an
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3628
     existing image may confuse later pixel interpretation
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3629
     (it does not care for colormaps and/or cached device image flushing)."
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3630
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3631
    self bits:aByteArrayArg.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3632
    self mask:maskArg
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3633
!
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3634
4115
0e783379a6b0 Use ByteArray for bitsPerSample (255 should be enough ;-)
Stefan Vogel <sv@exept.de>
parents: 4109
diff changeset
  3635
bitsPerSample:aCollection
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3636
    "set the number of bits per sample.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3637
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3638
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3639
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3640
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3641
7373
61933c223183 added metaData instVar (for free use by image reader)
Claus Gittinger <cg@exept.de>
parents: 7363
diff changeset
  3642
    "/ 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
  3643
    "/ at least for the most common cases.
7363
778803c164cd #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7349
diff changeset
  3644
    "/ Prevents writers to do what is described above.
778803c164cd #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7349
diff changeset
  3645
    "/ 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
  3646
    bitsPerSample :=
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3647
        #(
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3648
            #[ 8 8 8 ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3649
            #[ 4 4 4 ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3650
            #[ 8 ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3651
            #[ 4 ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3652
            #[ 2 ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3653
            #[ 1 ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3654
        ) detect:[:bps | bps sameContentsAs:aCollection] ifNone:[aCollection asByteArray].
7363
778803c164cd #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7349
diff changeset
  3655
6899
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  3656
    samplesPerPixel isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3657
        samplesPerPixel := bitsPerSample size.
6899
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  3658
    ].
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3659
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3660
    "Modified: 23.4.1996 / 11:08:31 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3661
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3662
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3663
depth:d
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3664
    "set the depth of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3665
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3666
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3667
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3668
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3669
1362
454d644f6ff7 set depth & bitsPerPixel for ST-80 compatibility.
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
  3670
    depth := self depth.
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
  3671
    "/ bitsPerPixel := d.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3672
    d == 24 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3673
        samplesPerPixel := 3.
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  3674
        bitsPerSample := #[8 8 8]
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3675
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3676
        d == 32 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3677
            samplesPerPixel := 4.
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  3678
            bitsPerSample := #[8 8 8 8]
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3679
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3680
            d == 16 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3681
                samplesPerPixel := 3.
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  3682
                bitsPerSample := #[5 5 5].
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3683
                "/ bitsPerPixel := 15.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3684
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3685
                samplesPerPixel := 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3686
                bitsPerSample := ByteArray with:d
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3687
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3688
        ]
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3689
    ]
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3690
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  3691
    "Modified: / 27-05-2007 / 16:59:47 / cg"
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  3692
    "Modified: / 30-01-2017 / 19:36:00 / stefan"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3693
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3694
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3695
extent:anExtent
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3696
    "set the images extent.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3697
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3698
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3699
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3700
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3701
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3702
    width := anExtent x.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3703
    height := anExtent y
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3704
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3705
    "Modified: 23.4.1996 / 11:08:38 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3706
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3707
5326
0443d8649cac *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5319
diff changeset
  3708
hasAlphaChannel
0443d8649cac *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5319
diff changeset
  3709
    ^ false
0443d8649cac *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5319
diff changeset
  3710
!
0443d8649cac *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5319
diff changeset
  3711
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3712
height:aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3713
    "set the height of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3714
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3715
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3716
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3717
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3718
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3719
    height := aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3720
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3721
    "Modified: 23.4.1996 / 11:08:40 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3722
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3723
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3724
photometric:aSymbol
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3725
    "set the photometric interpretation of the pixel values.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3726
     The argument, aSymbol is one of:
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3727
        #blackIs0, #whiteIs0, #palette, #rgb
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3728
     See TIFF documentation, from which the photometric concept is borrowed.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3729
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3730
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3731
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3732
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3733
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3734
    |b|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3735
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3736
    photometric := aSymbol.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3737
    bitsPerSample isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3738
        photometric == #rgb ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3739
            b := self class imageDepth // 3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3740
            bitsPerSample := ByteArray with:b with:b with:b
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3741
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3742
            bitsPerSample := ByteArray with:(self class imageDepth)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3743
        ].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3744
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3745
    samplesPerPixel isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3746
        photometric == #rgb ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3747
            samplesPerPixel := 3
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3748
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3749
            samplesPerPixel := 1
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3750
        ]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3751
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3752
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3753
    "Modified: 10.6.1996 / 18:21:29 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3754
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3755
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3756
samplesPerPixel:aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3757
    "set the array of samples per pixel.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3758
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3759
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3760
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3761
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3762
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3763
    samplesPerPixel := aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3764
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3765
    "Modified: 23.4.1996 / 11:08:45 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3766
!
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3767
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3768
width:aNumber
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3769
    "set the width of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3770
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3771
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3772
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3773
     existing image may confuse later pixel interpretation."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3774
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3775
    width := aNumber
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3776
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3777
    "Modified: 23.4.1996 / 11:08:48 / cg"
100
1b0b86c77397 co !!:*
claus
parents: 89
diff changeset
  3778
!
1b0b86c77397 co !!:*
claus
parents: 89
diff changeset
  3779
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3780
width:w height:h
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3781
    "set the width and height of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3782
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3783
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3784
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3785
     existing image may confuse later pixel interpretation."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3786
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3787
    width := w.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3788
    height := h
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3789
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3790
    "Modified: 23.4.1996 / 11:08:53 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3791
!
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3792
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3793
width:w height:h depth:d
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3794
    "set the width, height and depth of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3795
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3796
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3797
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3798
     existing image may confuse later pixel interpretation."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3799
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3800
    width := w.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3801
    height := h.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3802
    self depth:d.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3803
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3804
    "Modified: 23.4.1996 / 11:08:56 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  3805
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  3806
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3807
width:w height:h depth:d fromArray:bits
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3808
    "set the width, height, depth and pixels of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3809
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3810
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3811
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3812
     existing image may confuse later pixel interpretation."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3813
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3814
    width := w.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3815
    height := h.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3816
    self depth:d.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3817
    self bits:bits
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3818
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3819
    "Modified: 23.4.1996 / 11:08:59 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3820
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3821
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3822
width:w height:h depth:d palette:aColormap
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3823
    "set the width, height and depth of the image.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3824
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3825
     This interface is only to be used when initializing
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3826
     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
  3827
     existing image may confuse later pixel interpretation."
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3828
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3829
    width := w.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3830
    height := h.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3831
    self depth:d.
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  3832
    self setColorMap:aColormap.
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3833
    aColormap notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3834
        photometric := #palette
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  3835
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3836
        photometric := #blackIs0
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  3837
    ].
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3838
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3839
    "Modified: 23.4.1996 / 11:08:56 / cg"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3840
    "Created: 6.3.1997 / 15:23:57 / cg"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3841
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3842
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3843
width:w height:h photometric:p
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3844
    "set the width, height and photometric of the image.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3845
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3846
     This interface is only to be used when initializing
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3847
     instances or by image readers. Calling for a change of an
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3848
     existing image may confuse later pixel interpretation."
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3849
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3850
    width := w.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3851
    height := h.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3852
    self photometric:p.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3853
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3854
    "Modified: 23.4.1996 / 11:08:56 / cg"
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3855
!
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3856
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3857
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
  3858
    "set all relevant internal state of the image.
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
894
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3864
    ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3865
        width:w
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3866
        height:h
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3867
        photometric:p
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3868
        samplesPerPixel:spp
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3869
        bitsPerSample:bps
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3870
        colorMap:cm
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3871
        bits:pixels
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3872
        mask:nil
894
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3873
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3874
    "Modified: 20.6.1996 / 17:10:24 / cg"
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3875
!
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3876
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3877
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
  3878
    "set all relevant internal state of the image.
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3879
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3880
     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
  3881
     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
  3882
     existing image may confuse later pixel interpretation."
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3883
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3884
    width := w.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3885
    height := h.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3886
    photometric := p.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3887
    samplesPerPixel := spp.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3888
    bitsPerSample := bps.
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  3889
    self setColorMap:cm.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3890
    self bits:pixels.
894
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3891
    mask := m.
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3892
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3893
    "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
  3894
    "Created: 20.6.1996 / 17:09:53 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3895
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
  3896
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  3897
2205
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3898
!Image methodsFor:'conversion helpers'!
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3899
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3900
rgbColormapFor:aDevice
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3901
    "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
  3902
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3903
    |nColors    "{ Class: SmallInteger }"
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3904
     scaleRed scaleGreen scaleBlue
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3905
     redShift   "{ Class: SmallInteger }"
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3906
     greenShift "{ Class: SmallInteger }"
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3907
     blueShift  "{ Class: SmallInteger }"
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3908
     colorValues|
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3909
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3910
    "/ 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
  3911
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3912
    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
  3913
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3914
    "/ 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
  3915
    "/ (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
  3916
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3917
    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
  3918
    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
  3919
    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
  3920
    redShift := aDevice shiftRed.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3921
    greenShift := aDevice shiftGreen.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3922
    blueShift := aDevice shiftBlue.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3923
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3924
    colorValues := Array uninitializedNew:nColors.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3925
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3926
    0 to:nColors-1 do:[:pixel |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3927
        |clr rv gv bv v "{ Class: SmallInteger }" |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3928
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3929
        clr := self colorFromValue:pixel.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3930
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3931
        rv := (clr red * scaleRed) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3932
        gv := (clr green * scaleGreen) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3933
        bv := (clr blue * scaleBlue) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3934
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3935
        v := rv bitShift:redShift.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3936
        v := v bitOr:(gv bitShift:greenShift).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3937
        v := v bitOr:(bv bitShift:blueShift).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3938
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  3939
        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
  3940
"/ clr print. ' ' print.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3941
"/ 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
  3942
"/ ' -> ' print. v printNL.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3943
    ].
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3944
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3945
    ^ colorValues
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3946
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3947
    "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
  3948
! !
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3949
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3950
!Image methodsFor:'converting'!
48194c26a46c Initial revision
claus
parents:
diff changeset
  3951
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3952
asBurkesDitheredMonochromeImage
837
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  3953
    "return a burkes dithered monochrome image from the receiver image.
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  3954
     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
  3955
     a floyd-steinberg dithered image.
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  3956
     Notice that floyd-steinberg dithering is faster; both because less
837
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  3957
     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
  3958
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3959
    |monoBits|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3960
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3961
    monoBits := self burkesDitheredMonochromeBits.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3962
    ^ 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
  3963
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3964
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3965
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3966
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  3967
     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
  3968
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3969
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3970
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3971
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3972
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3973
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3974
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3975
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3976
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  3977
     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
  3978
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3979
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3980
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3981
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3982
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3983
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3984
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3985
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3986
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3987
     i := Depth4Image
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  3988
             width:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  3989
             height:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  3990
             fromArray:#[
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  3991
                            16r01 16r23
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  3992
                            16r45 16r67
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  3993
                            16r89 16rab
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  3994
                            16rcd 16ref
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  3995
                        ].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3996
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3997
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3998
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3999
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4000
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4001
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4002
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4003
    "Created: 10.6.1996 / 12:34:44 / cg"
837
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  4004
    "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
  4005
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4006
3157
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  4007
asDitheredImageUsing:colors
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  4008
    "return a dithered image from the picture,
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  4009
     using colors in colors for dithering."
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  4010
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  4011
    ^ self asDitheredImageUsing:colors depth:self depth
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  4012
!
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  4013
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  4014
asDitheredImageUsing:colors depth:d
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  4015
    "return a dithered image from the picture,
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  4016
     using colors in colors for dithering."
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  4017
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  4018
    |newBits|
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  4019
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  4020
    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
  4021
    newBits isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4022
        self error:'dithering failed'
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3905
diff changeset
  4023
    ].
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4024
    ^ (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
  4025
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4026
    "Modified: / 30-01-2017 / 19:40:19 / stefan"
3157
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  4027
!
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  4028
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4029
asErrorDitheredMonochromeImage
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4030
    "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
  4031
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4032
    DitherAlgorithm == #burkes ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4033
        ^ self asBurkesDitheredMonochromeImage
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4034
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4035
    DitherAlgorithm == #stevensonArce ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4036
        ^ self asStevensonArceDitheredMonochromeImage
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4037
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4038
    ^ self asFloydSteinbergDitheredMonochromeImage
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4039
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4040
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4041
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4042
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4043
     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
  4044
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4045
     i asErrorDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4046
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4047
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4048
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4049
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4050
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4051
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4052
     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
  4053
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4054
     i asErrorDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4055
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4056
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4057
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4058
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4059
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4060
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4061
     i := Depth4Image
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4062
             width:4
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4063
             height:4
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4064
             fromArray:#[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4065
                            16r01 16r23
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4066
                            16r45 16r67
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4067
                            16r89 16rab
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4068
                            16rcd 16ref
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4069
                        ].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4070
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4071
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4072
     i asErrorDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4073
     i asOrderedDitheredMonochromeImage inspect.
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
    "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
  4077
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4078
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4079
asFloydSteinbergDitheredDepth8FormOn:aDevice colors:fixColors
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4080
    "return a floyd-steinberg dithered pseudoForm from the picture.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4081
     Use the colors in the fixColors array.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4082
     By passing the ditherColors as extra array, this method can
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4083
     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
  4084
     for example to create dithered Depth4Images from Depth8Images."
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4085
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4086
    |pseudoBits f deviceDepth map|
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4087
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4088
    deviceDepth := aDevice depth.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4089
    deviceDepth == 8 ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4090
        (aDevice supportedImageFormatForDepth:8) isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4091
            ^ nil.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4092
        ]
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4093
    ].
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4094
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4095
    pseudoBits := self floydSteinbergDitheredDepth8BitsColors:fixColors.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4096
    pseudoBits isNil ifTrue:[^ nil].
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4097
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4098
    f := Form width:width height:height depth:deviceDepth onDevice:aDevice.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4099
    f isNil ifTrue:[^ nil].
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4100
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4101
    "/
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4102
    "/ have to create a funny colorMap, where
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4103
    "/ color at:index == color colorId:index
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4104
    "/
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4105
    map := Array new:256.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4106
    fixColors do:[:clr |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4107
        map at:clr colorId + 1 put:clr
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4108
    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4109
    f colorMap:map.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4110
    f bits:pseudoBits.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4111
    aDevice
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4112
        drawBits:pseudoBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4113
        bitsPerPixel:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4114
        depth:deviceDepth
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4115
        padding:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4116
        width:width height:height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4117
        x:0 y:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4118
        into:(f id) x:0 y:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4119
        width:width height:height
7755
75f5eba88e77 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7689
diff changeset
  4120
        with:(f initGC).
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4121
    ^ f
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4122
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4123
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4124
     example:
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4125
        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
  4126
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4127
     |img8 reducedImg8 img4 map form|
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4128
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4129
     map := #(
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4130
                  (0     0   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4131
                  (0     0 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4132
                  (0    50   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4133
                  (0    50 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4134
                  (0   100   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4135
                  (0   100 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4136
                  (100   0   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4137
                  (100   0 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4138
                  (100  50   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4139
                  (100  50 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4140
                  (100 100   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4141
                  (100 100 100)) collect:[:rgb | (Color red:(rgb at:1)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4142
                                                      green:(rgb at:2)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4143
                                                       blue:(rgb at:3)) onDevice:Display].
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4144
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4145
     img8 := Image fromFile:'goodies/bitmaps/bf.im8'.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4146
     form := img8 paletteImageAsDitheredPseudoFormOn:Display
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4147
                      colors:map
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4148
                        nRed:2
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4149
                      nGreen:3
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4150
                       nBlue:2.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4151
     img8 := Depth8Image fromForm:form.    'dithered version of original image'.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4152
     img4 := Depth4Image fromImage:img8.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4153
    "
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4154
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4155
    "Modified: 14.6.1996 / 16:52:34 / cg"
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4156
    "Created: 23.6.1997 / 15:25:37 / cg"
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4157
!
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4158
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4159
asFloydSteinbergDitheredDepth8FormOn:aDevice colors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4160
    "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
  4161
     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
  4162
     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
  4163
     Color class.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4164
     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
  4165
     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
  4166
     for example to create dithered Depth4Images from Depth8Images."
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4167
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4168
    |pseudoBits f deviceDepth map|
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4169
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4170
    deviceDepth := aDevice depth.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4171
    deviceDepth == 8 ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4172
        (aDevice supportedImageFormatForDepth:8) isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4173
            ^ nil
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4174
        ]
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4175
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4176
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4177
    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
  4178
    pseudoBits isNil ifTrue:[^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4179
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4180
    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
  4181
    f isNil ifTrue:[^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4182
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4183
    "/
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4184
    "/ have to create a funny colorMap, where
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4185
    "/ color at:index == color colorId:index
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4186
    "/
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4187
    map := Array new:256.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4188
    fixColors do:[:clr |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4189
        map at:clr colorId + 1 put:clr
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4190
    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4191
    f colorMap:map.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4192
    f bits:pseudoBits.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4193
    aDevice
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4194
        drawBits:pseudoBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4195
        bitsPerPixel:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4196
        depth:deviceDepth
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4197
        padding:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4198
        width:width height:height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4199
        x:0 y:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4200
        into:(f id) x:0 y:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4201
        width:width height:height
7755
75f5eba88e77 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7689
diff changeset
  4202
        with:(f initGC).
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4203
    ^ f
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4204
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4205
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4206
     example:
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4207
        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
  4208
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4209
     |img8 reducedImg8 img4 map form|
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4210
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4211
     map := #(
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4212
                  (0     0   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4213
                  (0     0 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4214
                  (0    50   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4215
                  (0    50 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4216
                  (0   100   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4217
                  (0   100 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4218
                  (100   0   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4219
                  (100   0 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4220
                  (100  50   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4221
                  (100  50 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4222
                  (100 100   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4223
                  (100 100 100)) collect:[:rgb | (Color red:(rgb at:1)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4224
                                                      green:(rgb at:2)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4225
                                                       blue:(rgb at:3)) onDevice:Display].
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4226
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4227
     img8 := Image fromFile:'goodies/bitmaps/bf.im8'.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4228
     form := img8 paletteImageAsDitheredPseudoFormOn:Display
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4229
                      colors:map
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4230
                        nRed:2
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4231
                      nGreen:3
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4232
                       nBlue:2.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4233
     img8 := Depth8Image fromForm:form.    'dithered version of original image'.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4234
     img4 := Depth4Image fromImage:img8.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4235
    "
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4236
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4237
    "Modified: 14.6.1996 / 16:52:34 / cg"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4238
!
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4239
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4240
asFloydSteinbergDitheredGrayFormOn:aDevice
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4241
    "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
  4242
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4243
    |depth bits|
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4244
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4245
    depth := aDevice depth.
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4246
    (depth == 1
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4247
    or:[aDevice hasGrayscales not]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4248
        "/ for monochrome, there is specialized
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4249
        "/ monochrome dither code available
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4250
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4251
        bits := self floydSteinbergDitheredMonochromeBits.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4252
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4253
        bits := self floydSteinbergDitheredGrayBitsDepth:depth.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4254
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4255
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4256
    ^ 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
  4257
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4258
    "
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4259
     |i|
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4260
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4261
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4262
     (i asFloydSteinbergDitheredGrayFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4263
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4264
841
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  4265
    "
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4266
     |i|
841
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  4267
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  4268
     i := Image fromFile:'bitmaps/granite.tiff'.
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  4269
     (i asFloydSteinbergDitheredGrayFormOn:Display) inspect
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  4270
    "
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  4271
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4272
    "Created: 10.6.1996 / 14:11:39 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  4273
    "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
  4274
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4275
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4276
asFloydSteinbergDitheredGrayImageDepth:depth
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4277
    "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
  4278
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4279
    |ditheredBits|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4280
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4281
    (depth == 1) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4282
        ^ self asFloydSteinbergDitheredMonochromeImage
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4283
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4284
1779
34f9e24f330e method rename
Claus Gittinger <cg@exept.de>
parents: 1778
diff changeset
  4285
    ditheredBits := self floydSteinbergDitheredGrayBitsDepth:depth.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4286
    ^ (self class implementorForDepth:depth)
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4287
        width:width height:height fromArray:ditheredBits
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4288
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4289
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4290
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4291
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4292
     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
  4293
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4294
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4295
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4296
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4297
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4298
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4299
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4300
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4301
829
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4302
     i := Depth24Image width:4 height:1
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4303
          fromArray:#[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4304
            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
  4305
            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
  4306
            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
  4307
            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
  4308
     i := i magnifiedBy:4@1.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4309
     i inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4310
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4311
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4312
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4313
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4314
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4315
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4316
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4317
     |i|
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4318
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4319
     i := Depth24Image width:4 height:6
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4320
          fromArray:#[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4321
            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
  4322
            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
  4323
            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
  4324
            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
  4325
            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
  4326
            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
  4327
     i := i magnifiedBy:30.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4328
     i inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4329
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4330
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4331
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4332
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4333
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4334
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4335
     |i|
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4336
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4337
     i := Image fromFile:'granite.tiff'.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4338
     i inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4339
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4340
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4341
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4342
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4343
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4344
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4345
     |i|
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4346
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4347
     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
  4348
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4349
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4350
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4351
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4352
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4353
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4354
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4355
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4356
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4357
     i := Depth4Image
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4358
             width:4
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4359
             height:4
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4360
             fromArray:#[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4361
                            16r01 16r23
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4362
                            16r45 16r67
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4363
                            16r89 16rab
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4364
                            16rcd 16ref
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4365
                        ].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4366
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4367
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4368
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4369
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4370
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4371
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4372
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4373
    "Created: 10.6.1996 / 12:33:47 / cg"
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  4374
    "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
  4375
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4376
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4377
asFloydSteinbergDitheredMonochromeFormOn:aDevice
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4378
    "return a dithered moncohrome form from the receiver image."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4379
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4380
    |monoBits|
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4381
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4382
    monoBits := self floydSteinbergDitheredMonochromeBits.
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4383
    ^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4384
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4385
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4386
     |i f|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4387
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4388
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4389
     (i asFloydSteinbergDitheredMonochromeFormOn:Display) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4390
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4391
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4392
    "
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4393
     |i f|
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4394
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4395
     i := Depth2Image width:8 height:8
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4396
          fromArray:#[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4397
                        4r0000 4r0000
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4398
                        4r0000 4r0000
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4399
                        4r1111 4r1111
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4400
                        4r1111 4r1111
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4401
                        4r2222 4r2222
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4402
                        4r2222 4r2222
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4403
                        4r3333 4r3333
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4404
                        4r3333 4r3333
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4405
                     ].
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4406
     (i asFloydSteinbergDitheredMonochromeFormOn:Display) inspect.
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4407
    "
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4408
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4409
    "Created: 10.6.1996 / 14:11:39 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  4410
    "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
  4411
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4412
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4413
asFloydSteinbergDitheredMonochromeImage
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4414
    "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
  4415
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4416
    |monoBits|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4417
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4418
    monoBits := self floydSteinbergDitheredMonochromeBits.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4419
    ^ 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
  4420
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4421
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4422
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4423
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4424
     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
  4425
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4426
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4427
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4428
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4429
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4430
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4431
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4432
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4433
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4434
     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
  4435
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4436
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4437
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4438
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4439
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4440
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4441
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4442
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4443
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4444
     i := Depth4Image
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4445
             width:4
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4446
             height:4
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4447
             fromArray:#[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4448
                            16r01 16r23
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4449
                            16r45 16r67
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4450
                            16r89 16rab
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4451
                            16rcd 16ref
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4452
                        ].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4453
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4454
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4455
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4456
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4457
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4458
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4459
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4460
    "Created: 10.6.1996 / 12:33:47 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  4461
    "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
  4462
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4463
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4464
asFloydSteinbergDitheredPseudoFormUsing:colors on:aDevice
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4465
    "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
  4466
     using colors in colors for dithering."
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4467
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4468
    |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
  4469
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4470
    deviceDepth := aDevice depth.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4471
    has8BitImage := (deviceDepth == 8)
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4472
                    or:[ (aDevice supportedImageFormatForDepth:8) notNil ].
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4473
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  4474
    has8BitImage ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4475
        deviceDepth == 4 ifFalse:[^ nil].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4476
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4477
        pseudoBits8 := self nfloydSteinbergDitheredDepth8BitsColors:colors.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4478
        pseudoBits8 isNil ifTrue:[^ nil].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4479
        "/ convert to devices depth
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4480
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4481
        pseudoBits := ByteArray new:(width*4+7//8 * height).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4482
        pseudoBits8 compressPixels:4 width:width height:height into:pseudoBits mapping:nil.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4483
        d := 4.
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  4484
    ] ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4485
        pseudoBits := self nfloydSteinbergDitheredDepth8BitsColors:colors.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4486
        pseudoBits isNil ifTrue:[^ nil].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4487
        d := 8.
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4488
    ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4489
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4490
    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
  4491
    f isNil ifTrue:[^ nil].
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4492
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4493
    "/
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4494
    "/ have to create a funny colorMap, where
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4495
    "/ color at:index == color colorId:index
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4496
    "/
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4497
    map := Array new:256 withAll:0.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4498
    colors do:[:clr |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4499
        clr notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4500
            map at:clr colorId + 1 put:clr
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4501
        ]
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4502
    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4503
    f colorMap:map.
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4504
    f bits:pseudoBits.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4505
    aDevice
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4506
        drawBits:pseudoBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4507
        bitsPerPixel:d
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4508
        depth:deviceDepth
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4509
        padding:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4510
        width:width height:height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4511
        x:0 y:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4512
        into:(f id) x:0 y:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4513
        width:width height:height
7755
75f5eba88e77 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7689
diff changeset
  4514
        with:(f initGC).
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4515
    ^ f
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4516
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4517
    "
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4518
     |i|
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4519
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4520
     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
  4521
     (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
  4522
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4523
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4524
     |i|
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4525
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4526
     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
  4527
     (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
  4528
    "
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4529
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4530
    "Created: 17.6.1996 / 12:13:35 / cg"
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  4531
    "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
  4532
!
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4533
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4534
asFormOn:aDevice
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4535
    "get a device form, with best possible approximation.
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4536
     remember it in case someone asks again."
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4537
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  4538
    |form visual|
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4539
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4540
    ((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ deviceForm].
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4541
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
  4542
    mask notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4543
        mask := mask onDevice:aDevice
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4544
    ].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4545
    bytes isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4546
        pixelFunction notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4547
            self computeBitsFromPixelFunction.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4548
        ]
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
  4549
    ].
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
  4550
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4551
    (aDevice depth == 1
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4552
    or:[aDevice hasGrayscales not]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4553
        form := self asMonochromeFormOn:aDevice.
2212
ddc9cb6aeb73 more caching if device forms.
Claus Gittinger <cg@exept.de>
parents: 2206
diff changeset
  4554
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4555
        ((visual := aDevice visualType) == #StaticGray) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4556
            form := self asGrayFormOn:aDevice.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4557
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4558
            (visual == #PseudoColor
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4559
             or:[visual == #StaticColor]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4560
                form := self asPseudoFormQuickOn:aDevice.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4561
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4562
        ]
2212
ddc9cb6aeb73 more caching if device forms.
Claus Gittinger <cg@exept.de>
parents: 2206
diff changeset
  4563
    ].
ddc9cb6aeb73 more caching if device forms.
Claus Gittinger <cg@exept.de>
parents: 2206
diff changeset
  4564
ddc9cb6aeb73 more caching if device forms.
Claus Gittinger <cg@exept.de>
parents: 2206
diff changeset
  4565
    form isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4566
        "/ kludge: repair a 'should not happen' situation...
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4567
        photometric isNil ifTrue:[ self repairPhotometric ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4568
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4569
        (photometric == #palette) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4570
            form := self paletteImageAsFormOn:aDevice
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4571
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4572
            (photometric == #rgb or:[photometric == #rgba or:[photometric == #argb]]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4573
                form := self rgbImageAsFormOn:aDevice
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4574
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4575
                (photometric == #cmy or:[photometric == #cmyk]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4576
                    form := self rgbImageAsFormOn:aDevice
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4577
                ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4578
                    form := self greyImageAsFormOn:aDevice
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4579
                ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4580
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4581
        ].
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4582
    ].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4583
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4584
    (device isNil or:[aDevice == device]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4585
        "remember this form in the receiver ..."
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4586
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4587
        form notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4588
            form := form asImageForm.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4589
            deviceForm := form.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4590
            maskedPixelsAre0 := nil.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4591
            device isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4592
                device := aDevice.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4593
                Lobby register:self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4594
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4595
                Lobby registerChange:self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4596
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4597
            mask notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4598
                self clearMaskedPixels.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4599
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4600
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4601
            "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4602
             can save space, by not keeping the images data-bits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4603
             twice (here and in the device form)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4604
            "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4605
            form forgetBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4606
        ]
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4607
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
  4608
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4609
    ^ form
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4610
4173
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  4611
    "
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  4612
     |i|
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  4613
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  4614
     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
  4615
     (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
  4616
    "
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  4617
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4618
    "Modified: / 06-06-2007 / 12:18:43 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4619
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4620
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4621
asGrayFormOn:aDevice
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4622
    "get a gray device form"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4623
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4624
    ^ self asGrayFormOn:aDevice dither:DitherAlgorithm.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4625
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4626
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4627
     |i|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4628
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4629
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4630
     (i asGrayFormOn:Display) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4631
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4632
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4633
    "Modified: 10.6.1996 / 17:39:30 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4634
    "Created: 10.6.1996 / 18:44:42 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4635
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4636
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4637
asGrayFormOn:aDevice dither:aDitherAlgorithm
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4638
    "get a greyscale device form, using aDitherAlgorithm."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4639
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4640
    |depth|
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4641
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4642
    depth := aDevice depth.
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4643
    (depth == 1
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4644
    or:[aDevice hasGrayscales not]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4645
        ^ self asMonochromeFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4646
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4647
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4648
    (aDitherAlgorithm isNil
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4649
    or:[aDitherAlgorithm == #threshold]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4650
        ^ self asThresholdGrayFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4651
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4652
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4653
    (aDitherAlgorithm == #pattern
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4654
    or:[aDitherAlgorithm == #ordered]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4655
        ^ self asOrderedDitheredGrayFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4656
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4657
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4658
    ^ self asFloydSteinbergDitheredGrayFormOn:aDevice.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4659
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4660
    "Created: 10.6.1996 / 18:42:01 / cg"
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  4661
    "Modified: 14.6.1996 / 15:17:28 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4662
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4663
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4664
asGrayImageDepth:depthArg
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4665
    "get a gray image from the receiver"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4666
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4667
    ((self colorMap notNil and:[depthArg between:self depth and:8])
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4668
     or:[self depth >= 8 "do need for dither" ]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4669
        ^ self copyWithColorMapProcessing:[:clr | Color brightness:(clr brightness)].
4417
5e5d9b696293 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  4670
    ].
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4671
    ^ self asGrayImageDepth:depthArg dither:DitherAlgorithm.
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4672
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4673
    "
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4674
     |i|
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4675
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4676
     i := Image fromFile:'../../goodies/bitmaps/gifImages/claus.gif'.
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4677
     (i asGrayImageDepth:16).
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4678
     (i asGrayImageDepth:4).
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4679
    "
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4680
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4681
    "Modified: / 10-06-1996 / 17:39:30 / cg"
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4682
    "Created: / 10-06-1996 / 19:07:08 / cg"
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4683
    "Modified: / 30-01-2017 / 20:13:06 / stefan"
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4684
    "Modified (comment): / 31-01-2017 / 13:25:29 / stefan"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4685
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4686
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4687
asGrayImageDepth:depth dither:aDitherAlgorithm
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4688
    "get a greyscale image, using aDitherAlgorithm."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4689
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4690
    (aDitherAlgorithm isNil
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4691
    or:[aDitherAlgorithm == #threshold]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4692
        ^ self asThresholdGrayImageDepth:depth
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4693
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4694
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4695
    (aDitherAlgorithm == #pattern
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4696
    or:[aDitherAlgorithm == #ordered]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4697
        ^ self asOrderedDitheredGrayImageDepth:depth
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4698
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4699
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4700
    ^ self asFloydSteinbergDitheredGrayImageDepth:depth
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4701
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4702
    "Created: 10.6.1996 / 19:08:21 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4703
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  4704
4423
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4705
asImageWithDepth:depth
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4706
    "return a new image with another depth. Notice that this
7242
bf3a75233d55 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7230
diff changeset
  4707
     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
  4708
     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
  4709
     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
  4710
     In the other case, use one of the dithering converters"
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4711
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4712
    |imageClass|
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4713
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4714
    imageClass := Image implementorForDepth:depth.
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4715
    ^ imageClass fromImage:self
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4716
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4717
    "
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4718
     |i|
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4719
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4720
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4721
     (i asImageWithDepth:24) inspect.
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4722
    "
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4723
    "
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4724
     |i|
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4725
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4726
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4727
     (i asImageWithDepth:4) inspect.
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4728
    "
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4729
!
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4730
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4731
asMonochromeFormOn:aDevice
48194c26a46c Initial revision
claus
parents:
diff changeset
  4732
    "get a monochrome device form"
48194c26a46c Initial revision
claus
parents:
diff changeset
  4733
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4734
    |form|
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4735
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4736
    ((aDevice == device) and:[monoDeviceForm notNil]) ifTrue:[^ monoDeviceForm].
4390
8d752f4cd9e2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  4737
    self depth == 1 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4738
        ((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ deviceForm].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4739
        ^ self asFormOn:aDevice
1935
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
  4740
    ].
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4741
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4742
    form := self asMonochromeFormOn:aDevice dither:DitherAlgorithm.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4743
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4744
    (device isNil or:[aDevice == device]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4745
        "remember this form in the receiver ..."
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4746
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4747
        form notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4748
            form := form asImageForm.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4749
            monoDeviceForm := form.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4750
            device isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4751
                device := aDevice.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4752
                Lobby register:self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4753
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4754
                Lobby registerChange:self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4755
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4756
            "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4757
             can save space, by not keeping the images data-bits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4758
             twice (here and in the device form)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4759
            "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4760
            form forgetBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4761
        ]
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4762
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
  4763
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4764
    ^ form
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4765
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4766
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4767
     |i|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4768
4173
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  4769
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4770
     (i asMonochromeFormOn:Display) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4771
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4772
1935
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
  4773
    "Modified: 23.10.1997 / 00:44:59 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4774
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4775
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4776
asMonochromeFormOn:aDevice dither:aDitherAlgorithm
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4777
    "get a monochrome device form, using aDitherAlgorithm."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4778
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4779
    |monoBits|
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4780
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4781
    (aDitherAlgorithm isNil
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4782
    or:[aDitherAlgorithm == #threshold]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4783
        ^ self asThresholdMonochromeFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4784
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4785
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4786
    aDitherAlgorithm == #burkes ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4787
        monoBits := self burkesDitheredMonochromeBits.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4788
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4789
        aDitherAlgorithm == #stevensonArce ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4790
            monoBits := self stevensonArceDitheredMonochromeBits.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4791
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4792
            (aDitherAlgorithm == #pattern
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4793
            or:[aDitherAlgorithm == #ordered]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4794
                ^ self asOrderedDitheredGrayFormOn:aDevice.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4795
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4796
                ^ self asFloydSteinbergDitheredMonochromeFormOn:aDevice.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4797
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4798
        ]
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
    "/
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4802
    "/ make its pixel interpretation correct for the device
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4803
    "/
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4804
    ^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4805
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4806
    "Modified: 10.6.1996 / 20:18:05 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4807
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4808
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4809
asNearestPaintDepth8FormOn:aDevice colors:fixColors
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4810
    "return a nearest paint pseudoForm from the palette picture.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4811
     Use the colors in the fixColors array.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4812
     By passing the ditherColors as extra array, this method can
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4813
     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
  4814
     for example to create dithered Depth4Images from Depth8Images."
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4815
3914
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4816
    ^ 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
  4817
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4818
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4819
     example:
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4820
        color reduction from Depth8 to Depth4 can be done by:
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4821
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4822
     |img8 reducedImg8 img4 map form|
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4823
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4824
     map := #(
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4825
                  (0     0   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4826
                  (0     0 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4827
                  (0    50   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4828
                  (0    50 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4829
                  (0   100   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4830
                  (0   100 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4831
                  (100   0   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4832
                  (100   0 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4833
                  (100  50   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4834
                  (100  50 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4835
                  (100 100   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4836
                  (100 100 100)) collect:[:rgb | (Color red:(rgb at:1)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4837
                                                      green:(rgb at:2)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4838
                                                       blue:(rgb at:3)) onDevice:Display].
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4839
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4840
     img8 := Image fromFile:'goodies/bitmaps/claus.gif'.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4841
     form := img8 asNearestPaintDepth8FormOn:Display
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4842
                      colors:map
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4843
                        nRed:2
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4844
                      nGreen:3
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4845
                       nBlue:2.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4846
     img8 := Depth8Image fromForm:form.    'dithered version of original image'.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4847
     img4 := Depth4Image fromImage:img8.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4848
    "
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4849
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4850
    "Modified: 17.6.1996 / 18:52:47 / cg"
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4851
    "Created: 23.6.1997 / 15:26:09 / cg"
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4852
!
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4853
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4854
asNearestPaintDepth8FormOn:aDevice colors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4855
    "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
  4856
     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
  4857
     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
  4858
     Color class.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4859
     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
  4860
     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
  4861
     for example to create dithered Depth4Images from Depth8Images."
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4862
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4863
    |pseudoBits f deviceDepth map|
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4864
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4865
    deviceDepth := aDevice depth.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4866
    deviceDepth == 8 ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4867
        (aDevice supportedImageFormatForDepth:8) isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4868
            ^ nil
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4869
        ]
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4870
    ].
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4871
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4872
    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
  4873
    pseudoBits isNil ifTrue:[^ nil].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4874
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4875
    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
  4876
    f isNil ifTrue:[^ nil].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4877
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4878
    "/
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4879
    "/ have to create a funny colorMap, where
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4880
    "/ color at:index == color colorId:index
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4881
    "/
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4882
    map := Array new:256.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4883
    fixColors do:[:clr |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4884
        map at:clr colorId + 1 put:clr
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4885
    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4886
    f colorMap:map.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4887
    f bits:pseudoBits.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4888
    aDevice
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4889
        drawBits:pseudoBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4890
        bitsPerPixel:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4891
        depth:deviceDepth
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4892
        padding:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4893
        width:width height:height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4894
        x:0 y:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4895
        into:(f id) x:0 y:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4896
        width:width height:height
7755
75f5eba88e77 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7689
diff changeset
  4897
        with:(f initGC).
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4898
    ^ f
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4899
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4900
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4901
     example:
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4902
        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
  4903
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4904
     |img8 reducedImg8 img4 map form|
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4905
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4906
     map := #(
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4907
                  (0     0   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4908
                  (0     0 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4909
                  (0    50   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4910
                  (0    50 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4911
                  (0   100   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4912
                  (0   100 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4913
                  (100   0   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4914
                  (100   0 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4915
                  (100  50   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4916
                  (100  50 100)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4917
                  (100 100   0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4918
                  (100 100 100)) collect:[:rgb | (Color red:(rgb at:1)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4919
                                                      green:(rgb at:2)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4920
                                                       blue:(rgb at:3)) onDevice:Display].
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4921
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4922
     img8 := Image fromFile:'goodies/bitmaps/claus.gif'.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4923
     form := img8 asNearestPaintDepth8FormOn:Display
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4924
                      colors:map
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4925
                        nRed:2
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4926
                      nGreen:3
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4927
                       nBlue:2.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4928
     img8 := Depth8Image fromForm:form.    'dithered version of original image'.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4929
     img4 := Depth4Image fromImage:img8.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4930
    "
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4931
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4932
    "Created: 17.6.1996 / 18:47:46 / cg"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4933
    "Modified: 17.6.1996 / 18:52:47 / cg"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4934
!
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4935
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4936
asNearestPaintImageDepth:d colors:colors
3914
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4937
    "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
  4938
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4939
    |newBits|
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4940
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4941
    d ~~ 8 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4942
        self error:'unsupported depth'
3914
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4943
    ].
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4944
    newBits := self nearestPaintDepth8BitsColors:colors nRed:nil nGreen:nil nBlue:nil.
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4945
    newBits isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4946
        self error:'conversion failed'
3914
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4947
    ].
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4948
    ^ (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
  4949
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  4950
    "Modified: / 30-01-2017 / 19:40:28 / stefan"
3914
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4951
!
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4952
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4953
asOrderedDitheredGrayFormOn:aDevice
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4954
    "return a dithered depth-x grey form from the receiver image.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4955
     Uses an 8x8 dithermatrix."
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4956
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4957
    |depth bits|
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4958
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4959
    depth := aDevice depth.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4960
    (depth == 1
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4961
    or:[aDevice hasGrayscales not]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4962
        "/ for monochrome, there is highly specialized
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4963
        "/ monochrome dither code available
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4964
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4965
        ^ self asOrderedDitheredMonochromeFormOn:aDevice
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4966
    ].
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4967
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4968
    bits := self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4969
                orderedDitheredGrayBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4970
                ditherWidth:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4971
                depth:depth.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4972
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4973
    ^ self makeDeviceGrayPixmapOn:aDevice depth:depth fromArray:bits
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4974
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4975
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4976
     |i|
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4977
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4978
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4979
     (i asOrderedDitheredGrayFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4980
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4981
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  4982
    "Modified: 24.6.1997 / 22:19:30 / cg"
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4983
!
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4984
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4985
asOrderedDitheredGrayImageDepth:depth
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4986
    "return a dithered depth-x grey image from the receiver image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4987
     Uses an 8x8 dithermatrix."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4988
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4989
    |dither|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4990
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4991
    dither := self class orderedDitherMatrixOfSize:8.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4992
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4993
    (depth == 1) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4994
        "/ for monochrome, there is highly specialized
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4995
        "/ monochrome dither code available
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4996
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4997
        ^ Depth1Image
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4998
            width:width
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  4999
            height:height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5000
            fromArray:(
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5001
                self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5002
                    orderedDitheredMonochromeBitsWithDitherMatrix:dither
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5003
                    ditherWidth:8)
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5004
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5005
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5006
    ^ (self class implementorForDepth:depth)
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5007
        width:width
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5008
        height:height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5009
        fromArray:(
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5010
            self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5011
                orderedDitheredGrayBitsWithDitherMatrix:dither
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5012
                ditherWidth:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5013
                depth:depth)
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5014
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5015
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5016
     |i i1 i2 i4 i8|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5017
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5018
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5019
     i1 := i asOrderedDitheredGrayImageDepth:1.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5020
     i1 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5021
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5022
     i2 := i asOrderedDitheredGrayImageDepth:2.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5023
     i2 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5024
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5025
     i4 := i asOrderedDitheredGrayImageDepth:4.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5026
     i4 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5027
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5028
     i8 := i asOrderedDitheredGrayImageDepth:8.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5029
     i8 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5030
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5031
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5032
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5033
     |i i1 i2 i4 i8|
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5034
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5035
     i1 := i asOrderedDitheredGrayImageDepth:1.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5036
     i1 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5037
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5038
     i2 := i asOrderedDitheredGrayImageDepth:2.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5039
     i2 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5040
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5041
     i4 := i asOrderedDitheredGrayImageDepth:4.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5042
     i4 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5043
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5044
     i8 := i asOrderedDitheredGrayImageDepth:8.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5045
     i8 inspect.
800
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  5046
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  5047
     i2 := i8 asOrderedDitheredGrayImageDepth:2.
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  5048
     i2 inspect.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5049
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5050
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5051
    "Created: 7.6.1996 / 18:03:54 / cg"
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  5052
    "Modified: 24.6.1997 / 22:19:36 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5053
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5054
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5055
asOrderedDitheredMonochromeFormOn:aDevice
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5056
    "return a dithered monochrome form from the grey image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5057
     Uses a 4x4 dithermatrix."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5058
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5059
    "/ 4x4 seems a good comprimize between:
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5060
    "/    number of grey levels (8x8 is better)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5061
    "/    artifacts             (4x4 is better)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5062
    "/
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5063
    "/ could look at the image and decide upon the number of
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5064
    "/ distinct colors present. Use 8x8 for high-number,
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5065
    "/ 4x4 for small number of colors ...
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5066
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5067
    ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5068
        asOrderedDitheredMonochromeFormOn:aDevice
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5069
        ditherMatrix:(self class orderedDitherMatrixOfSize:4)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5070
        ditherWidth:4
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5071
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5072
"/    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5073
"/        asOrderedDitheredMonochromeFormOn:aDevice
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5074
"/        ditherMatrix:(self class orderedDitherMatrixOfSize:8)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5075
"/        ditherWidth:8
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5076
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5077
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5078
     |i f|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5079
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5080
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5081
     f := i asOrderedDitheredMonochromeFormOn:Display.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5082
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5083
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5084
     |i f|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5085
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5086
     i := (Image fromFile:'goodies/bitmaps/winBitmaps/a11.ico') magnifiedBy:10.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5087
     f := i asOrderedDitheredMonochromeFormOn:Display.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5088
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
     |i f|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5091
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5092
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5093
     f := i asOrderedDitheredMonochromeFormOn:Display.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5094
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5095
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5096
     |i f|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5097
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5098
     i := (Image fromFile:'doc/online/pictures/PasteButton.gif') magnifiedBy:10.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5099
     f := i asOrderedDitheredMonochromeFormOn:Display.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5100
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5101
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5102
     |i f|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5103
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5104
     i := (Image fromFile:'goodies/bitmaps/gifImages/blue-ball.gif') magnifiedBy:1.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5105
     f := i asOrderedDitheredMonochromeFormOn:Display.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5106
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5107
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5108
    "Created: 7.6.1996 / 14:52:32 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  5109
    "Modified: 17.4.1997 / 01:10:10 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5110
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5111
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5112
asOrderedDitheredMonochromeFormOn:aDevice ditherMatrix:ditherMatrix ditherWidth:dW
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5113
    "return a dithered monochrome form from the image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5114
     Uses the passed ditherMatrix and ditherWidth."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5115
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  5116
    |monoBits|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5117
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5118
    monoBits := self orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW.
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  5119
    ^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5120
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5121
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5122
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5123
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5124
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5125
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5126
     (i asOrderedDitheredMonochromeFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5127
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5128
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5129
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5130
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5131
     i := Image fromFile:'goodies/bitmaps/granite.tiff'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5132
     (i asOrderedDitheredMonochromeFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5133
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5134
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5135
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5136
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5137
     i := (Image fromFile:'goodies/bitmaps/PasteButton.tiff') magnifiedBy:10.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5138
     (i asOrderedDitheredMonochromeFormOn:Display) inspect
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5139
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5140
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5141
    "Created: 7.6.1996 / 14:51:42 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  5142
    "Modified: 17.4.1997 / 01:08:24 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5143
!
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
asOrderedDitheredMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5146
    "return a dithered monochrome image from the receiver image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5147
     Uses a 4x4 dithermatrix."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5148
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5149
    "/ 4x4 seems a good comprimize between:
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5150
    "/    number of grey levels (8x8 is better)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5151
    "/    artifacts             (4x4 is better)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5152
    "/
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5153
    "/ could look at the image and decide upon the number of
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5154
    "/ distinct colors present. Use 8x8 for high-number,
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5155
    "/ 4x4 for small number of colors ...
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5156
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5157
    ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5158
        asOrderedDitheredMonochromeImageWithDitherMatrix:(self class orderedDitherMatrixOfSize:4)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5159
        ditherWidth:4
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5160
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5161
"/    ^ self
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5162
"/        asOrderedDitheredMonochromeImageWithDitherMatrix:(self class orderedDitherMatrixOfSize:8)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5163
"/        ditherWidth:8
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5164
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5165
    "
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5166
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5167
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5168
     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
  5169
     i asOrderedDitheredMonochromeImage inspect
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5170
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5171
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5172
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5173
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5174
     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
  5175
     i asOrderedDitheredMonochromeImage inspect
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5176
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5177
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5178
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5179
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5180
     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
  5181
     i asOrderedDitheredMonochromeImage inspect
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5182
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5183
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5184
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5185
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5186
     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
  5187
     i asOrderedDitheredMonochromeImage inspect
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5188
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5189
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5190
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5191
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5192
     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
  5193
     i asOrderedDitheredMonochromeImage inspect
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5194
    "
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
    "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
  5197
    "Modified: 10.6.1996 / 11:15:09 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5198
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5199
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5200
asOrderedDitheredMonochromeImageWithDitherMatrix:ditherMatrix ditherWidth:dW
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5201
    "return a dithered monochrome image from the receiver image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5202
     Uses the passed ditherMatrix and ditherWidth."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5203
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5204
    |monoBits|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5205
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5206
    monoBits := self orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5207
    ^ (Depth1Image width:width height:height fromArray:monoBits) photometric:#blackIs0
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
    "order-4 dither:
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5210
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5211
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5212
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5213
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5214
     i
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5215
        asOrderedDitheredMonochromeImageWithDitherMatrix:(Image orderedDitherMatrixOfSize:4)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5216
        ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5217
    "
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
    "order-6 dither:
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5220
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5221
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5222
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5223
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5224
     i
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5225
        asOrderedDitheredMonochromeImageWithDitherMatrix:(Image orderedDitherMatrixOfSize:8)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5226
        ditherWidth:8
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5227
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5228
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5229
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5230
    "thresholding at:0.5 (all above 0.5 becomes white):
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5231
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5232
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5233
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5234
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5235
     i
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5236
        asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:8)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5237
        ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5238
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5239
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5240
    "thresholding at: 0.25 (all above 0.25 becomes white):
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
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5243
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5244
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5245
     i
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5246
        asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:3)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5247
        ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5248
    "
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
    "thresholding at: 0.75 (all above 0.75 becomes white):
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5251
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5252
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5253
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5254
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5255
     i
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5256
        asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:11)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5257
        ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5258
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5259
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5260
    "Modified: 7.6.1996 / 17:23:47 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5261
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5262
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5263
asPseudoFormQuickOn:aDevice
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5264
    "return a pseudo-deviceForm from the image.
878
b99add8dc742 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 874
diff changeset
  5265
     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
  5266
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5267
    |f d
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5268
     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
  5269
     w            "{ Class: SmallInteger }"
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  5270
     h            "{ Class: SmallInteger }"
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  5271
     dDev         "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5272
     nClr         "{ Class: SmallInteger }"
2772
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  5273
     bytesPerLine "{ Class: SmallInteger }"
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  5274
     usedColors pix fmt bytes|
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5275
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5276
    d := self depth.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5277
    (d == 1
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5278
    or:[d == 2
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5279
    or:[d == 4
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5280
    or:[d == 8]]]) ifFalse:[^ nil].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5281
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  5282
    bytes := self bits.
2772
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  5283
    w := width.
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  5284
    h := height.
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  5285
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5286
    "/ 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
  5287
    "/ if the padding is not supported: fail
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5288
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5289
    dDev := aDevice depth.
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5290
    (bytesPerLine := dDev) == 8 ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5291
        bytesPerLine := (w * dDev + 7) // 8.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5292
    ].
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5293
2532
Claus Gittinger <cg@exept.de>
parents: 2530
diff changeset
  5294
    fmt := aDevice supportedImageFormatForDepth:dDev.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5295
    fmt isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5296
        "/ cannot draw directly
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5297
        ^ nil
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5298
    ].
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5299
    (bytesPerLine * 8) \\ (fmt at:#padding) == 0 ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5300
        "/ mhmh - ought to repad here;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5301
        "/ however, the nonQuick converter does it.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5302
        ^ nil
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5303
    ].
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5304
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5305
    "/ see if all of the images colors are representable
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5306
    "/ on the device
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5307
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5308
    bits := self bitsPerPixel.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5309
    nClr := (1 bitShift:bits).
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5310
    cMap := Array new:nClr.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5311
    idMap := ByteArray new:nClr.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5312
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5313
    photometric == #palette ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5314
        nClr := nClr min:(colorMap size)
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5315
    ].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5316
878
b99add8dc742 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 874
diff changeset
  5317
    d == 8 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5318
        usedColors := bytes usedValues.    "gets us an array filled with used values"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5319
        1 to:nClr do:[:pixel |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5320
            (usedColors includes:(pixel - 1)) ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5321
                clr := Color black
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5322
            ] ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5323
                clr := self colorFromValue:pixel-1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5324
                clr := clr exactOn:aDevice.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5325
                clr isNil ifTrue:[^ nil].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5326
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5327
            (pix := clr colorId) isNil ifTrue:[^ nil].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5328
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5329
            cMap at:(pixel) put:clr.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5330
            idMap at:(pixel) put:pix.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5331
        ].
878
b99add8dc742 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 874
diff changeset
  5332
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5333
        1 to:nClr do:[:pixel |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5334
            clr := self colorFromValue:pixel-1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5335
            clr := clr exactOn:aDevice.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5336
            clr isNil ifTrue:[^ nil].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5337
            (pix := clr colorId) isNil ifTrue:[^ nil].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5338
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5339
            cMap at:(pixel) put:clr.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5340
            idMap at:(pixel) put:pix.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5341
        ].
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5342
    ].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5343
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5344
    "/ got all colors; good - simply change depth & translate pixels
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5345
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5346
    (d == 8 and:[dDev == 8]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5347
        "/ only translate
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5348
        temp := ByteArray uninitializedNew:(w * h).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5349
        bytes expandPixels:8         "xlate only"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5350
                    width:w
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5351
                   height:h
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5352
                     into:temp
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5353
                  mapping:idMap.
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5354
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5355
        "/ stupid: expandPixels can only handle any-to-8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5356
        "/ compressPixels can only handle 8-to-any
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5357
        "/ However, those methods are faster
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5358
        "/ - even if we convert twice.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5359
        "/ Therefore, convert first from myDepth to 8,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5360
        "/ then from 8 to the device depth.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5361
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5362
        d ~~ 8 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5363
            temp8 := ByteArray uninitializedNew:(w * h).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5364
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5365
            bytes expandPixels:d
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5366
                         width:w
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5367
                        height:h
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5368
                          into:temp8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5369
                       mapping:idMap.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5370
            idMap := nil.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5371
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5372
            temp8 := bytes.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5373
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5374
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5375
        dDev ~~ 8 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5376
            temp := ByteArray uninitializedNew:(bytesPerLine * h).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5377
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5378
            temp8 compressPixels:dDev
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5379
                         width:w
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5380
                        height:h
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5381
                          into:temp
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5382
                       mapping:idMap.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5383
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5384
            temp := temp8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5385
        ].
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5386
    ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5387
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5388
    f := Form width:w height:h depth:dDev onDevice:aDevice.
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5389
    f isNil ifTrue:[^ nil].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5390
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5391
    f colorMap:cMap.
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5392
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5393
    aDevice
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5394
        drawBits:temp
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5395
        depth:dDev
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5396
        padding:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5397
        width:w
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5398
        height:h
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5399
        x:0 y:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5400
        into:(f id) x:0 y:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5401
        width:w
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5402
        height:h
7755
75f5eba88e77 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7689
diff changeset
  5403
        with:(f initGC).
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5404
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5405
    ^ f
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5406
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5407
    "
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5408
     (
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5409
        (((Depth4Image
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5410
             width:4
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5411
             height:4
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5412
             fromArray:#[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5413
                            16r01 16r23
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5414
                            16r45 16r67
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5415
                            16r89 16rab
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5416
                            16rcd 16ref
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5417
                        ]))
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5418
               magnifiedBy:30
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5419
         )
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5420
          asPseudoFormQuickOn:Display
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5421
      ) inspect
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5422
     "
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5423
2113
c64f89f9ffba checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2102
diff changeset
  5424
    "Modified: / 7.5.1998 / 19:40:47 / cg"
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5425
!
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5426
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5427
asStevensonArceDitheredMonochromeImage
837
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  5428
    "return a stevenson-arce dithered monochrome image from the receiver image.
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  5429
     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
  5430
     a floyd-steinberg dithered image.
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  5431
     Notice that floyd-steinberg dithering is faster; both because less
837
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  5432
     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
  5433
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5434
    |monoBits|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5435
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5436
    monoBits := self stevensonArceDitheredMonochromeBits.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5437
    ^ (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
  5438
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5439
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5440
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5441
5161
d6538957b675 changed #asStevensonArceDitheredMonochromeImage
sr
parents: 5160
diff changeset
  5442
     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
  5443
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5444
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5445
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5446
     i asStevensonArceDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5447
     i asOrderedDitheredMonochromeImage inspect.
5161
d6538957b675 changed #asStevensonArceDitheredMonochromeImage
sr
parents: 5160
diff changeset
  5448
     (i asThresholdMonochromeImage:0.5) inspect
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5449
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5450
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5451
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5452
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5453
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5454
     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
  5455
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5456
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5457
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5458
     i asStevensonArceDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5459
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5460
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5461
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5462
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5463
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5464
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5465
     i := Depth4Image
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  5466
             width:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  5467
             height:4
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  5468
             fromArray:#[
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  5469
                            16r01 16r23
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  5470
                            16r45 16r67
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  5471
                            16r89 16rab
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  5472
                            16rcd 16ref
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  5473
                        ].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5474
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5475
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5476
     i asStevensonArceDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5477
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5478
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5479
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5480
    "Created: 10.6.1996 / 12:38:29 / cg"
837
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  5481
    "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
  5482
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5483
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5484
asThresholdGrayFormOn:aDevice
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5485
    "return a thresholded grey form from the receiver image."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5486
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5487
    |depth|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5488
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5489
    (depth := aDevice depth) == 1 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5490
        ^ self asThresholdMonochromeFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5491
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5492
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5493
    ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5494
        makeDeviceGrayPixmapOn:aDevice
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5495
        depth:depth
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5496
        fromArray:(self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5497
                        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
  5498
                        ditherWidth:4
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5499
                        depth:depth)
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5500
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5501
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5502
     |i|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5503
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5504
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5505
     (i asThresholdGrayFormOn:Display) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5506
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5507
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5508
    "Created: 10.6.1996 / 18:38:31 / cg"
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  5509
    "Modified: 24.6.1997 / 22:19:46 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5510
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5511
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5512
asThresholdGrayImageDepth:depth
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5513
    "return a thresholded depth-x grey image from the receiver image."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5514
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  5515
    (depth == 1) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5516
        "/ for monochrome, there is highly specialized
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5517
        "/ monochrome dither code available
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
        ^ Depth1Image
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5520
            width:width
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5521
            height:height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5522
            fromArray:(
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5523
                self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5524
                    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
  5525
                    ditherWidth:4)
800
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  5526
    ].
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  5527
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5528
    ^ (self class implementorForDepth:depth)
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5529
        width:width
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5530
        height:height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5531
        fromArray:(
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5532
            self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5533
                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
  5534
                ditherWidth:4
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5535
                depth:depth)
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5536
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5537
    "
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5538
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5539
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5540
     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
  5541
     (i asThresholdGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5542
     (i asThresholdGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5543
     (i asThresholdGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5544
     (i asThresholdGrayImageDepth:8) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5545
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5546
     (i asOrderedDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5547
     (i asOrderedDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5548
     (i asOrderedDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5549
     (i asOrderedDitheredGrayImageDepth:8) inspect.
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
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5552
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5553
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5554
     (i asFloydSteinbergDitheredGrayImageDepth:8) inspect.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5555
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5556
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5557
    "Created: 7.6.1996 / 18:13:33 / cg"
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  5558
    "Modified: 24.6.1997 / 22:19:52 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5559
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5560
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5561
asThresholdMonochromeFormOn:aDevice
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5562
    "return a threshold monochrome form from the image."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5563
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5564
    ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5565
        asOrderedDitheredMonochromeFormOn:aDevice
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5566
        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
  5567
        ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5568
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5569
    "
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5570
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5571
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5572
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5573
     i inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5574
     (i asThresholdMonochromeFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5575
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5576
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5577
     |i|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5578
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5579
     i := (Image fromFile:'goodies/bitmaps/a11.ico') magnifiedBy:10.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5580
     i inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5581
     (i asThresholdMonochromeFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5582
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5583
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5584
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5585
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5586
     i := Image fromFile:'goodies/bitmaps/granite.tiff'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5587
     i inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5588
     (i asThresholdMonochromeFormOn:Display) inspect
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
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5591
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5592
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5593
     i := (Image fromFile:'goodies/bitmaps/PasteButton.tiff') magnifiedBy:10.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5594
     i inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5595
     (i asThresholdMonochromeFormOn:Display) inspect
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5596
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5597
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5598
    "Created: 7.6.1996 / 16:15:17 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5599
    "Modified: 10.6.1996 / 17:44:29 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5600
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5601
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5602
asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5603
    "return a threshold monochrome image from the image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5604
     Threshold means: brightness < 0.5 -> black / otherwise white"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5605
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5606
    ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5607
        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
  5608
        ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5609
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5610
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5611
     |i i2|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5612
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5613
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5614
     i2 := i asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5615
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5616
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5617
     |i i2|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5618
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5619
     i := (Image fromFile:'/cdrom/icons/a/a11.ico') magnifiedBy:10.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5620
     i2 := i asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5621
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5622
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5623
     |i i2|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5624
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5625
     i := Image fromFile:'goodies/bitmaps/granite.tiff'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5626
     i2 := i asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5627
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5628
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5629
     |i i2|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5630
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5631
     i := (Image fromFile:'goodies/bitmaps/PasteButton.tiff') magnifiedBy:10.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5632
     i2 := i asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5633
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5634
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5635
    "Created: 7.6.1996 / 16:15:17 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5636
    "Modified: 7.6.1996 / 17:16:10 / cg"
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
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5639
asThresholdMonochromeImage:thresholdBrighness
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5640
    "return a threshold monochrome image from the image.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5641
     The argument (0..1) gives the threshold value;
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5642
     Threshold means: brightness < threshold -> black / otherwise white"
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5643
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5644
    |value ditherMatrix|
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5645
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5646
    value := thresholdBrighness * 255.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5647
    ditherMatrix := ByteArray new:256 withAll:(value truncated).
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5648
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5649
    ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5650
        asOrderedDitheredMonochromeImageWithDitherMatrix:ditherMatrix
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5651
        ditherWidth:16
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5652
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5653
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5654
     |i|
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5655
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5656
     i := Image width:4 height:4 depth:4
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5657
                fromArray:#[ 16r01 16r23
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5658
                             16r45 16r67
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5659
                             16r89 16rab
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5660
                             16rcd 16ref ].
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5661
     i := i magnifiedBy:30.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5662
     i inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5663
     (i asThresholdMonochromeImage:0.125) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5664
     (i asThresholdMonochromeImage:0.25) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5665
     (i asThresholdMonochromeImage:0.5) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5666
     (i asThresholdMonochromeImage:0.75) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5667
     (i asThresholdMonochromeImage:1) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5668
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5669
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5670
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5671
     |i|
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5672
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5673
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5674
     i inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5675
     (i asThresholdMonochromeImage:0.125) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5676
     (i asThresholdMonochromeImage:0.25) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5677
     (i asThresholdMonochromeImage:0.5) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5678
     (i asThresholdMonochromeImage:0.625) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5679
     (i asThresholdMonochromeImage:0.75) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5680
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5681
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5682
    "Created: 7.6.1996 / 16:15:17 / cg"
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5683
    "Modified: 8.6.1996 / 14:51:57 / cg"
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5684
!
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5685
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5686
clearMaskedPixels
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5687
    "assuming that I already have a device representation
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5688
     in deviceForm, clear any masked pixels.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5689
     This will allow faster drawing in the future."
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5690
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5691
    maskedPixelsAre0 == true ifTrue:[^ self].   "/ already cleared
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5692
    mask isNil ifTrue:[^ self].         "/ no mask
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5693
    deviceForm isNil ifTrue:[^ self].   "/ no device rep.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5694
    mask depth ~~ 1 ifTrue:[^ self].    "/ not done with alpha masks
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5695
7494
70c399ea367b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7484
diff changeset
  5696
    deviceForm clearMaskedPixels:(mask asFormOn:device).
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5697
    maskedPixelsAre0 := true.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5698
6496
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  5699
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5700
    "Created: 12.4.1997 / 12:18:05 / cg"
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5701
    "Modified: 12.4.1997 / 12:20:19 / cg"
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5702
!
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5703
3104
edc88b280153 added #exactOn: - for Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3092
diff changeset
  5704
exactOn:aDevice
3107
ed51e2c00f1d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3105
diff changeset
  5705
    "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
  5706
edc88b280153 added #exactOn: - for Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3092
diff changeset
  5707
    ^ self onDevice:aDevice
edc88b280153 added #exactOn: - for Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3092
diff changeset
  5708
!
edc88b280153 added #exactOn: - for Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3092
diff changeset
  5709
3105
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5710
exactOrNearestOn:aDevice
3107
ed51e2c00f1d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3105
diff changeset
  5711
    "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
  5712
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5713
    ^ self onDevice:aDevice
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5714
!
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5715
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5716
fromForm:aForm
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  5717
    "setup the receiver from a form"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5718
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5719
    |map c0 c1|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5720
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5721
    width := aForm width.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5722
    height := aForm height.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5723
    bitsPerSample := self bitsPerSample.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5724
    samplesPerPixel := self samplesPerPixel.
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5725
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5726
    aForm hasBits ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5727
        "/ must read the data from the device
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5728
        self from:aForm in:(0@0 extent:aForm extent).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5729
        ^ self
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5730
    ].
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5731
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5732
    "/ the form has all data available
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5733
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  5734
    self bits:(aForm bits).
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5735
    map := aForm colorMap.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5736
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5737
    aForm depth == 1 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5738
        map isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5739
            photometric := #whiteIs0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5740
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5741
            c0 := map at:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5742
            c1 := map at:2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5743
            ((c0 = Color white)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5744
            and:[c1 = Color black]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5745
                photometric := #whiteIs0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5746
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5747
                ((c0 = Color black)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5748
                and:[c1 = Color white]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5749
                    photometric := #blackIs0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5750
                ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5751
                    photometric := #palette.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5752
                    self setColorMap:(Array with:c0 with:c1).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5753
                ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5754
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5755
        ]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5756
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5757
        map notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5758
            photometric := #palette.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5759
            self setColorMap:(map copy).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5760
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5761
            "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5762
             photometric stays at default
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5763
             (which is rgb for d24, greyscale for others)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5764
            "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5765
        ]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5766
    ].
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  5767
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5768
    "Modified: 5.7.1996 / 16:24:31 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5769
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5770
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5771
fromImage:anImage
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5772
    "setup the receiver from another image.
4888
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5773
     Color precision may be lost, if conversion is from a higher depth image.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5774
     WARNING:
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5775
     This implementation is a slow fallback (the loop over the
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5776
     source pixels is very slow). If this method is used heavily, you
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5777
     may want to redefine it in concrete subclasses for common source images."
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5778
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5779
    ^ 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
  5780
!
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5781
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5782
fromImage:anImage photometric:photometricOrNil
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5783
    "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
  5784
     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
  5785
     WARNING:
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5786
     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
  5787
     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
  5788
     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
  5789
3363
de7e8628d329 fixed conversion of 3-3-2 8-bit truecolor images
Claus Gittinger <cg@exept.de>
parents: 3273
diff changeset
  5790
    |map clr mappedRowPixels samePhotometric
1784
25b96d8904c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1783
diff changeset
  5791
     h "{ Class: SmallInteger }"
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  5792
     w "{ Class: SmallInteger }" myDepth otherDepth|
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5793
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5794
    width := anImage width.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5795
    height := anImage height.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5796
    bitsPerSample := self bitsPerSample.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5797
    samplesPerPixel := self samplesPerPixel.
4859
553f9013f270 only try to fetch colormap for palette images
Claus Gittinger <cg@exept.de>
parents: 4858
diff changeset
  5798
4888
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5799
    photometricOrNil isNil ifTrue:[
7689
6ada06895459 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7688
diff changeset
  5800
        photometric := self class defaultPhotometric
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5801
        "/ photometric := anImage photometric
4888
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5802
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5803
        photometricOrNil == #rgba ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5804
            samplesPerPixel == 3 ifTrue:[ photometric := #rgb ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5805
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5806
            photometric := photometricOrNil
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5807
        ].
4888
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5808
    ].
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5809
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5810
    photometric == #palette ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5811
        self colormapFromImage:anImage photometric:photometric.
4859
553f9013f270 only try to fetch colormap for palette images
Claus Gittinger <cg@exept.de>
parents: 4858
diff changeset
  5812
    ].
1374
ab515c0576c6 preserve mask when creating an image from another image.
Claus Gittinger <cg@exept.de>
parents: 1362
diff changeset
  5813
    self mask:anImage mask.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5814
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  5815
    samePhotometric := photometric == anImage photometric.
7272
4ec4788352ce #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7271
diff changeset
  5816
    myDepth := self depth.
4ec4788352ce #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7271
diff changeset
  5817
    otherDepth := anImage depth.
4ec4788352ce #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7271
diff changeset
  5818
4ec4788352ce #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7271
diff changeset
  5819
    ((myDepth = otherDepth) and:[samePhotometric]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5820
        self bits:(anImage bits copy).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5821
        ^ self.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  5822
    ].
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  5823
7272
4ec4788352ce #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7271
diff changeset
  5824
    self bits:(ByteArray new: "uninitializedNew:"(self bytesPerRow * height)).
4ec4788352ce #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7271
diff changeset
  5825
4ec4788352ce #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7271
diff changeset
  5826
    myDepth >= otherDepth ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5827
        otherDepth <= 12 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5828
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5829
            "/ if my depth is greater, all colors can be represented,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5830
            "/ and the loop can be done over pixel values ...
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5831
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5832
            (colorMap isNil or:[samePhotometric not]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5833
                map := Array new:(1 bitShift:otherDepth).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5834
                1 to:map size do:[:i |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5835
                    clr := anImage colorFromValue:(i - 1).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5836
                    map at:i put:(self valueFromColor:clr).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5837
                ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5838
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5839
            mappedRowPixels := self pixelArraySpecies new:width.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5840
            h := height-1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5841
            w := width.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5842
            0 to:h do:[:row |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5843
                anImage rowAt:row into:mappedRowPixels startingAt:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5844
                map notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5845
                    1 to:w do:[:i |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5846
                        mappedRowPixels at:i put:(map at:(mappedRowPixels at:i)+1)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5847
                    ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5848
                ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5849
                self rowAt:row putAll:mappedRowPixels
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5850
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5851
            ^ self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5852
        ].
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5853
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5854
5712
b4d960599bc8 changed: #fromImage:photometric:
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  5855
    "/ a hack, for now - alpha is in the low-byte !!!!!!
7272
4ec4788352ce #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7271
diff changeset
  5856
    (myDepth == 24 and:[otherDepth == 32]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5857
        (samePhotometric and:[photometric == #rgb]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5858
            "/ can do the bits by simple stripping off the alpha channel
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5859
            self copyPixels32AlphaLowTo24From:anImage.
7272
4ec4788352ce #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7271
diff changeset
  5860
"/    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
  5861
"/        |a r g b rgbPixel|
4ec4788352ce #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7271
diff changeset
  5862
"/
4ec4788352ce #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7271
diff changeset
  5863
"/        "/ bgra-pixel
4ec4788352ce #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7271
diff changeset
  5864
"/        "/ a := pixel bitAnd:16rFF.
4ec4788352ce #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7271
diff changeset
  5865
"/        r := (pixel bitShift:-8) bitAnd:16rFF.
4ec4788352ce #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7271
diff changeset
  5866
"/        g := (pixel bitShift:-16) bitAnd:16rFF.
4ec4788352ce #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7271
diff changeset
  5867
"/        b := (pixel bitShift:-24) bitAnd:16rFF.
4ec4788352ce #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7271
diff changeset
  5868
"/        rgbPixel := r + (g bitShift:8) + (b bitShift:16).
4ec4788352ce #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7271
diff changeset
  5869
"/        self pixelAtX:x y:y put:rgbPixel
4ec4788352ce #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7271
diff changeset
  5870
"/    ].
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5871
            ^ self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5872
        ].
5712
b4d960599bc8 changed: #fromImage:photometric:
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  5873
    ].
b4d960599bc8 changed: #fromImage:photometric:
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  5874
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5875
    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
  5876
        self colorAtX:x y:y put:clr
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5877
    ].
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5878
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5879
    "
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5880
     |i i2 i4 i8 i16 i24|
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5881
6496
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  5882
     i := GenericToolbarIconLibrary desktop32x32Icon2.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5883
     i inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5884
     i2 := Depth2Image fromImage:i.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5885
     i2 inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5886
     i4 := Depth4Image fromImage:i.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5887
     i4 inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5888
     i8 := Depth8Image fromImage:i.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5889
     i8 inspect.
6496
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  5890
     i16 := Depth16Image fromImage:i.
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  5891
     i16 inspect.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5892
     i24 := Depth24Image fromImage:i.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5893
     i24 inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5894
    "
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5895
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5896
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5897
     |i i24|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5898
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5899
     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
  5900
     Transcript showCR:(
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5901
        Time millisecondsToRun:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5902
            i24 := Depth24Image fromImage:i.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5903
        ]
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5904
     ).
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5905
     i24 inspect.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5906
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5907
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5908
     |i i24|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5909
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5910
     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
  5911
     MessageTally spyOn:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5912
        i24 := Depth24Image fromImage:i.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5913
     ]
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5914
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5915
7689
6ada06895459 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7688
diff changeset
  5916
    "Modified: / 22-11-2016 / 03:34:08 / cg"
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  5917
    "Modified (format): / 30-01-2017 / 20:46:22 / stefan"
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5918
!
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5919
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5920
fromSubImage:anImage in:aRectangle
7373
61933c223183 added metaData instVar (for free use by image reader)
Claus Gittinger <cg@exept.de>
parents: 7363
diff changeset
  5921
    "setup the receiver from another image, extracting a rectangular area.
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5922
     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
  5923
     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
  5924
     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
  5925
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5926
    |w h xL yT imgWidth imgHeight|
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5927
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5928
    w := aRectangle width.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5929
    h := aRectangle height.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5930
    xL := aRectangle left.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5931
    yT := aRectangle top.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5932
    imgWidth := anImage width.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5933
    imgHeight := anImage height.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5934
7373
61933c223183 added metaData instVar (for free use by image reader)
Claus Gittinger <cg@exept.de>
parents: 7363
diff changeset
  5935
    xL isFloat ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5936
        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
  5937
    ].
61933c223183 added metaData instVar (for free use by image reader)
Claus Gittinger <cg@exept.de>
parents: 7363
diff changeset
  5938
    yT isFloat ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5939
        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
  5940
    ].
61933c223183 added metaData instVar (for free use by image reader)
Claus Gittinger <cg@exept.de>
parents: 7363
diff changeset
  5941
    w isFloat ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5942
        w := (imgWidth * w) rounded.
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5943
    ].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5944
    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
  5945
    h isFloat ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5946
        h := (imgHeight * h) rounded.
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5947
    ].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5948
    h := h min:(imgHeight - yT).
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5949
    self fromSubImage:anImage inX:xL y:yT width:w height:h
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5950
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5951
    "
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5952
     |i i2 i4 i8 i16 i24|
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5953
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5954
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5955
     i inspect.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5956
     i4 := Depth4Image fromSubImage:i in:(300@160 corner:340@200).
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5957
     i4 inspect.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5958
     i8 := Depth8Image fromSubImage:i in:(300@160 corner:340@200).
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5959
     i8 inspect.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5960
     i24 := Depth24Image fromSubImage:i in:(300@160 corner:340@200).
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5961
     i24 inspect.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5962
    "
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5963
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5964
    "Created: / 20.9.1995 / 01:06:02 / claus"
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5965
    "Modified: / 20.9.1995 / 10:15:37 / claus"
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5966
    "Modified: / 18.5.1999 / 20:06:55 / cg"
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5967
!
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5968
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5969
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
  5970
    "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
  5971
     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
  5972
     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
  5973
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5974
     WARNING:
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5975
       This implementation is a slow fallback (the loop over the
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5976
       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
  5977
       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
  5978
       of creating a subImage with the same depth & palette."
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5979
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5980
    |xR yB imagesMask maskClass|
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5981
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5982
    width := w.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5983
    height := h.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5984
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
  5985
    self createPixelStore.
3458
b2e098e6288b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3457
diff changeset
  5986
    depth := self depth.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5987
    bitsPerSample := self bitsPerSample.
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
  5988
    "/ bitsPerPixel := self bitsPerPixel.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5989
    samplesPerPixel := self samplesPerPixel.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5990
    self colormapFromImage:anImage.
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5991
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5992
    xR := xL + w - 1.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5993
    yB := yT + h - 1.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5994
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5995
    ((photometric == anImage photometric)
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5996
    and:[self bitsPerPixel = anImage bitsPerPixel
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5997
    and:[colorMap = anImage colorMap]]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5998
        "/ can do it by value
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  5999
        anImage
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6000
            valuesFromX:xL y:yT toX:xR y:yB
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6001
            do:[:x :y :pixelValue | self pixelAtX:x-xL y:y-yT put:pixelValue ]
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  6002
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6003
        "/ must do it by colors
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6004
        anImage
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6005
            colorsFromX:xL y:yT toX:xR y:yB
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6006
            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
  6007
    ].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6008
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  6009
    (imagesMask := anImage mask) notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6010
        imagesMask depth == 1 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6011
            maskClass := ImageMask
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6012
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6013
            maskClass := imagesMask class.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6014
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6015
        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
  6016
    ].
1963
ab2d96e4e140 care for masks in copy/copySubImage;
tz
parents: 1962
diff changeset
  6017
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  6018
    "
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  6019
     |i i2 i4 i8 i16 i24|
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  6020
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  6021
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  6022
     i inspect.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  6023
     i4 := Depth4Image fromSubImage:i in:(300@160 corner:340@200).
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  6024
     i4 inspect.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  6025
     i8 := Depth8Image fromSubImage:i in:(300@160 corner:340@200).
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  6026
     i8 inspect.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  6027
     i24 := Depth24Image fromSubImage:i in:(300@160 corner:340@200).
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  6028
     i24 inspect.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  6029
    "
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  6030
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  6031
    "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
  6032
    "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
  6033
    "Modified: / 18.5.1999 / 20:06:55 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  6034
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  6035
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6036
monochromeOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6037
    "return a monochrome device image of the receiver for aDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6038
     (monochrome, even if device supports colors)"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6039
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6040
    ((aDevice == device) and:[monoDeviceForm notNil]) ifTrue:[^ self].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6041
    (device notNil and:[aDevice ~~ device]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6042
        "oops, I am already accociated to another device
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6043
         - need a copy ...
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6044
        "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6045
        ^ self copy monochromeOn:aDevice
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6046
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6047
    monoDeviceForm := self asMonochromeFormOn:aDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6048
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6049
3105
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  6050
nearestOn:aDevice
3107
ed51e2c00f1d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3105
diff changeset
  6051
    "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
  6052
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  6053
    ^ self onDevice:aDevice
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  6054
!
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  6055
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6056
on:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6057
    "return an image with the same pixels as the receiver, but
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6058
     associated to aDevice. If the receiver is not yet bound to
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6059
     a device, this will be the receiver. Otherwise, a new image
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6060
     is returned."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6061
3623
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  6062
    "/ send out a warning: #on: is typically used to create views
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  6063
    "/ operating on a model.
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  6064
    "/ Please use #onDevice: to avoid confusion.
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  6065
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  6066
    <resource:#obsolete>
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  6067
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  6068
    self obsoleteMethodWarning:'use #onDevice:'.
3477
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6069
    ^ self onDevice:aDevice
1496
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  6070
!
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  6071
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  6072
onDevice:aDevice
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  6073
    "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
  6074
     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
  6075
     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
  6076
     is returned."
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  6077
2980
409e9547a45c ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  6078
    aDevice isNil ifTrue:[^ self].
3477
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6079
    ((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ self].
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6080
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6081
    (device notNil and:[aDevice ~~ device]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6082
        "oops, I am already associated to another device
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6083
         - need a copy ...
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6084
        "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6085
        ^ self copy onDevice:aDevice
3477
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6086
    ].
7573
656c59bc93ad #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7565
diff changeset
  6087
    device := aDevice.
3477
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6088
    deviceForm := self asFormOn:aDevice.
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6089
    maskedPixelsAre0 := nil.
6496
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  6090
    mask notNil ifTrue:[
7573
656c59bc93ad #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7565
diff changeset
  6091
        mask := mask onDevice:aDevice.
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6092
        self clearMaskedPixels.
6496
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  6093
    ].
3477
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6094
    Lobby register:self
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6095
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6096
    "Modified: / 22.8.1998 / 13:34:24 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6097
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6098
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6099
!Image methodsFor:'converting greyscale images'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6100
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6101
greyImageAsFormOn:aDevice
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6102
    "return a grey-deviceForm from the grey image."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6103
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  6104
    |pictureDepth nPlanes|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6105
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  6106
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6107
    nPlanes := samplesPerPixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6108
    (nPlanes == 2) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6109
        'Image [info]: alpha plane ignored' infoPrintCR.
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  6110
    ].
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  6111
    "/ first plane only
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6112
    pictureDepth := bitsPerSample at:1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6113
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6114
    "monochrome is very easy ..."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6115
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6116
    (pictureDepth == 1) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6117
        ^ Form width:width height:height fromArray:self bits onDevice:aDevice
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6118
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6119
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6120
    (aDevice visualType == #TrueColor) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6121
        ^ self greyImageAsTrueColorFormOn:aDevice
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6122
    ].
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6123
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6124
    "/ PseudoColor conversion also works for StaticColor,
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6125
    "/ GrayScale and DirectColor; although possibly with suboptimal results
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6126
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6127
    ^ self greyImageAsPseudoFormOn:aDevice
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6128
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6129
    "Modified: 19.10.1997 / 05:17:25 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6130
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6131
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6132
greyImageAsPseudoFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6133
    "return an 8-bit pseudo Form from the grey image"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6134
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6135
    |wideBits pictureDepth f map
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6136
     colorMap usedColors nUsed aColor
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6137
     nColors "{ Class: SmallInteger }"
1766
08b918d293a6 fixed conversion of greyScale images with colorCube
Claus Gittinger <cg@exept.de>
parents: 1764
diff changeset
  6138
     range id
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6139
     cube nR nG nB grayColors
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6140
     fit|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6141
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6142
    pictureDepth := bitsPerSample at:1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6143
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6144
    (#[2 4 8] includes:pictureDepth) ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6145
        self error:'currently only depth-2, 4 or 8 supported'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6146
        ^ nil
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
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6149
    wideBits := ByteArray uninitializedNew:(width * height).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6150
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6151
    (pictureDepth == 8) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6152
        "for 8bits, we scan for used colors first;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6153
         to avoid allocating too many colors"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6154
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6155
        (grayColors := aDevice fixGrayColors) notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6156
            DitherAlgorithm == #floydSteinberg ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6157
                f := self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6158
                       asFloydSteinbergDitheredDepth8FormOn:aDevice
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6159
                       colors:grayColors
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6160
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6161
            f notNil ifTrue:[^ f].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6162
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6163
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6164
        (cube := aDevice fixColors) notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6165
            nR := aDevice numFixRed.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6166
            nG := aDevice numFixGreen.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6167
            nB := aDevice numFixBlue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6168
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6169
            DitherAlgorithm == #floydSteinberg ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6170
                f := self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6171
                       asFloydSteinbergDitheredDepth8FormOn:aDevice
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6172
                       colors:cube
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6173
                       nRed:nR
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6174
                       nGreen:nG
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6175
                       nBlue:nB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6176
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6177
                f := self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6178
                       asNearestPaintDepth8FormOn:aDevice
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6179
                       colors:cube
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6180
                       nRed:nR
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6181
                       nGreen:nG
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6182
                       nBlue:nB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6183
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6184
            f notNil ifTrue:[^ f].
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
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6187
        usedColors := self bits usedValues.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6188
        nUsed := usedColors max + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6189
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6190
        colorMap := Array new:nUsed.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6191
        range := 100 / 255.0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6192
        usedColors do:[:grey |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6193
            colorMap at:(grey + 1) put:(Color gray:(range * grey))
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6194
        ].
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  6195
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6196
        nColors := (1 bitShift:pictureDepth).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6197
        colorMap := Array new:nColors.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6198
        range := 100 / (nColors - 1) asFloat.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6199
        1 to:nColors do:[:i |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6200
            colorMap at:i put:(Color gray:(i - 1) * range).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6201
        ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6202
    ].
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6203
    photometric ~~ #blackIs0 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6204
        colorMap reverse
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6205
    ].
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6206
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6207
    "allocate those colors & setup the translation map"
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6208
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6209
    fit := true.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6210
    map := ByteArray uninitializedNew:256.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6211
    nColors := colorMap size.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6212
    1 to:nColors do:[:i |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6213
        aColor := colorMap at:i.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6214
        aColor notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6215
            aColor := aColor onDevice:aDevice.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6216
            colorMap at:i put:aColor.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6217
            id := aColor colorId.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6218
            id isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6219
                id := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6220
                fit := false.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6221
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6222
            map at:i put:id
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6223
        ]
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  6224
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6225
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6226
    fit ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6227
        "/ here comes the hard part - some grey value
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6228
        "/ could not be allocated.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6229
        "/ Must dither.
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6230
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6231
    ].
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6232
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6233
    "expand & translate"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6234
    self bits
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6235
        expandPixels:pictureDepth
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6236
        width:width height:height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6237
        into:wideBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6238
        mapping:map.
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  6239
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  6240
    f := Form width:width height:height depth:8 onDevice:aDevice.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6241
    f isNil ifTrue:[^ nil].
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6242
    f colorMap:colorMap.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6243
    aDevice
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6244
        drawBits:wideBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6245
        depth:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6246
        padding:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6247
        width:width height:height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6248
        x:0 y:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6249
        into:(f id)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6250
        x:0 y:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6251
        width:width height:height
7755
75f5eba88e77 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7689
diff changeset
  6252
        with:(f initGC).
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6253
    ^ f
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  6254
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6255
    "Modified: / 19-10-1997 / 05:19:44 / cg"
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6256
    "Modified: / 30-01-2017 / 19:37:01 / stefan"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6257
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  6258
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6259
greyImageAsTrueColorFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6260
    "return a true-color device-form for the grey-image receiver.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6261
     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
  6262
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  6263
    |myDepth    "{ Class: SmallInteger }"
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  6264
     nColors    "{ Class: SmallInteger }"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6265
     colorValues
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6266
     scaleDown
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  6267
     scaleRed   "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  6268
     scaleGreen "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  6269
     scaleBlue  "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  6270
     redShift   "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  6271
     blueShift  "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  6272
     greenShift "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6273
     form bestFormat usedDeviceDepth usedDeviceBitsPerPixel imageBits
1175
5595569cfbd3 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 1170
diff changeset
  6274
     greyValue  "{ Class: SmallInteger }"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6275
     h          "{ Class: SmallInteger }"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6276
     w          "{ Class: SmallInteger }"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6277
     pixelArray newPixelArray i|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6278
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6279
    "/ this is a slow fallback method; this ought to be
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6280
    "/ redefined in DepthxImage for more performance.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6281
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6282
    myDepth := self depth.
5315
cbac968cee6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5314
diff changeset
  6283
    myDepth > 16 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6284
        self error:'unsupported depth' mayProceed:true.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6285
        ^ nil
5315
cbac968cee6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5314
diff changeset
  6286
    ].
5314
517094dfa71c changed #greyImageAsTrueColorFormOn:
Claus Gittinger <cg@exept.de>
parents: 5313
diff changeset
  6287
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6288
    "/ compute scale to map from my pixels into devices range
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6289
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6290
    scaleDown := 1 bitShift:myDepth.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6291
    scaleRed := (1 bitShift:aDevice bitsRed).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6292
    scaleGreen := (1 bitShift:aDevice bitsGreen).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6293
    scaleBlue := (1 bitShift:aDevice bitsBlue).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6294
    redShift := aDevice shiftRed.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6295
    greenShift := aDevice shiftGreen.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6296
    blueShift := aDevice shiftBlue.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6297
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  6298
    "/ prepare the map
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  6299
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6300
    nColors := (1 bitShift:myDepth).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6301
    colorValues := Array new:nColors.
6256
1e510d7aea8e Inline block variable rename to avoid stc bug
Stefan Vogel <sv@exept.de>
parents: 6166
diff changeset
  6302
    1 to:nColors do:[:colorIdx |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6303
        |v gv bv rv nv|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6304
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6305
        "/ scale down to 0..1
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6306
        v := (colorIdx-1) / scaleDown.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6307
        rv := (v * scaleRed) truncated.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6308
        gv := (v * scaleGreen) truncated.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6309
        bv := (v * scaleBlue) truncated.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6310
        nv := rv bitShift:redShift.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6311
        nv := nv bitOr:(gv bitShift:greenShift).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6312
        nv := nv bitOr:(bv bitShift:blueShift).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6313
        colorValues at:colorIdx put:nv
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6314
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6315
    photometric == #whiteIs0 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6316
        "/ reverse the order; 0 is brightest
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6317
        colorValues reverse
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6318
    ].
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6319
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6320
    bestFormat := self bestSupportedImageFormatFor:aDevice.
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  6321
    usedDeviceDepth := bestFormat at:#depth.
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  6322
    usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6323
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6324
    "/ the temporary helper image is only needed to allow
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6325
    "/ the rowAt:putAll: calls below.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6326
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  6327
    i := (Image implementorForDepth:usedDeviceBitsPerPixel) new.
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  6328
    i width:width height:height.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
  6329
    i createPixelStore.
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
  6330
    imageBits := i bits.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6331
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6332
    "/ now, walk over the image and replace
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6333
    "/ colorMap indices by color values in the bits array
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6334
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6335
    h := height - 1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6336
    w := width - 1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6337
    pixelArray := self pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6338
    newPixelArray := i pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6339
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6340
    0 to:h do:[:y |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6341
        self rowAt:y into:pixelArray.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6342
        0 to:w do:[:x |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6343
            greyValue := pixelArray at:(x+1).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6344
            newPixelArray at:(x+1) put:(colorValues at:greyValue + 1).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6345
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6346
        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
  6347
    ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  6348
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  6349
    form := Form width:width height:height depth:usedDeviceDepth onDevice:aDevice.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6350
    form isNil ifTrue:[^ nil].
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6351
    form initGC.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6352
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6353
    form
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6354
        copyBitsFrom:imageBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6355
        bitsPerPixel:usedDeviceBitsPerPixel
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6356
        depth:usedDeviceDepth
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6357
        padding:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6358
        width:width height:height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6359
        x:0 y:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6360
        toX:0 y:0.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6361
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6362
    ^ form
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6363
5710
9928e8b52195 changed: #greyImageAsTrueColorFormOn:
Claus Gittinger <cg@exept.de>
parents: 5655
diff changeset
  6364
    "Created: / 20-10-1995 / 22:05:10 / cg"
9928e8b52195 changed: #greyImageAsTrueColorFormOn:
Claus Gittinger <cg@exept.de>
parents: 5655
diff changeset
  6365
    "Modified: / 05-02-2011 / 10:40:13 / cg"
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  6366
    "Modified (format): / 31-01-2017 / 14:42:05 / stefan"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6367
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
  6368
48194c26a46c Initial revision
claus
parents:
diff changeset
  6369
!Image methodsFor:'converting palette images'!
48194c26a46c Initial revision
claus
parents:
diff changeset
  6370
48194c26a46c Initial revision
claus
parents:
diff changeset
  6371
paletteImageAsFormOn:aDevice
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  6372
    "return a device-form for the palette-image receiver"
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  6373
380
c5ffc6d48a9e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 379
diff changeset
  6374
    |type ddepth|
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6375
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  6376
    ddepth := aDevice depth.
379
d74cdaa0adcb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
  6377
3940
b1b7dc76d7d7 not ifTrue -> ifFalse
Claus Gittinger <cg@exept.de>
parents: 3939
diff changeset
  6378
    aDevice hasGrayscales ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6379
        ^ self asMonochromeFormOn:aDevice
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  6380
    ].
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  6381
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6382
    type := aDevice visualType.
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6383
    (type == #StaticGray) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6384
        ddepth == 8 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6385
            ^ self paletteImageAsGray8FormOn:aDevice
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6386
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6387
        ^ self asGrayFormOn:aDevice
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6388
    ].
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  6389
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6390
    (type == #TrueColor) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6391
        DitherAlgorithm == #floydSteinberg ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6392
            ddepth == 8 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6393
                self depth == 8 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6394
                    "/ use fixColor dither algorithm
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6395
                    ^ self asDitheredTrueColor8FormOn:aDevice
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6396
                ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6397
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6398
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6399
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6400
        ^ self paletteImageAsTrueColorFormOn:aDevice
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6401
    ].
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6402
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6403
    "/ the PseudoColor conversion also works for
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6404
    "/ StaticColor, GrayScale & DirectColor; although possibly with suboptimal results
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6405
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6406
    ^ self paletteImageAsPseudoFormOn:aDevice
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6407
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6408
    "Modified: / 14-06-1996 / 19:31:01 / cg"
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6409
    "Modified: / 30-01-2017 / 20:55:32 / stefan"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6410
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  6411
48194c26a46c Initial revision
claus
parents:
diff changeset
  6412
paletteImageAsPseudoFormOn:aDevice
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  6413
    "return a pseudo-deviceForm from the palette image."
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6414
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  6415
    |tempImage d temp8|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  6416
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  6417
    d := self depth.
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6418
    (#[1 2 4 8] includes:d) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6419
        "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6420
         fallback code for some depth's:
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6421
         create a temporary Depth8Image and use its conversion method
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6422
        "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6423
        temp8 := ByteArray uninitializedNew:(width * height).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6424
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6425
        self bits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6426
            expandPixels:d
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6427
            width:width height:height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6428
            into:temp8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6429
            mapping:nil.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6430
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6431
        tempImage := Image width:width height:height depth:8 fromArray:temp8.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6432
        tempImage colorMap:colorMap.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6433
        ^ tempImage paletteImageAsPseudoFormOn:aDevice
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  6434
    ].
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  6435
    ^ self subclassResponsibility
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6436
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6437
    "Modified: / 30-01-2017 / 19:37:57 / stefan"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6438
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  6439
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6440
paletteImageAsTrueColorFormOn:aDevice
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6441
    "return a true-color device-form for the palette-image receiver."
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6442
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  6443
    |nColors "{ Class: SmallInteger }"
1605
64151392ff64 added generic #paletteImageAsTrueColorForm implementation
Claus Gittinger <cg@exept.de>
parents: 1595
diff changeset
  6444
     h       "{ Class: SmallInteger }"
64151392ff64 added generic #paletteImageAsTrueColorForm implementation
Claus Gittinger <cg@exept.de>
parents: 1595
diff changeset
  6445
     pixel   "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6446
     colorValues
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6447
     scaleRed scaleGreen scaleBlue redShift greenShift blueShift
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6448
     form imageBits bestFormat usedDeviceDepth usedDeviceBitsPerPixel
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6449
     i pixelArray newPixelArray
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6450
     clr r g b rv gv bv v "{ Class: SmallInteger }" |
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6451
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6452
    "/ this is a slow fallback method; this ought to be
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6453
    "/ redefined in DepthxImage for more performance.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6454
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6455
    bestFormat := self bestSupportedImageFormatFor:aDevice.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6456
    usedDeviceDepth := bestFormat at:#depth.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6457
    usedDeviceDepth == 1 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6458
        ^ self asMonochromeFormOn:aDevice.
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6459
    ].
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6460
    usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6461
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6462
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6463
    scaleRed := ((1 bitShift:aDevice bitsRed) - 1) / 255.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6464
    scaleGreen := ((1 bitShift:aDevice bitsGreen) - 1) / 255.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6465
    scaleBlue := ((1 bitShift:aDevice bitsBlue) - 1) / 255.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6466
    redShift := aDevice shiftRed.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6467
    greenShift := aDevice shiftGreen.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6468
    blueShift := aDevice shiftBlue.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6469
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6470
    nColors := colorMap size.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6471
    nColors <= 4096 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6472
        "/ precompute scales to map from 0..100 into devices range
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6473
        "/ (this may be different for the individual components)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6474
        colorValues := Array uninitializedNew:nColors.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6475
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6476
        1 to:nColors do:[:index |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6477
            r := colorMap redByteAt:index.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6478
            g := colorMap greenByteAt:index.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6479
            b := colorMap blueByteAt:index.
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6480
"/        clr := colorMap at:index.
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6481
            true "clr notNil" ifTrue:[
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6482
"/            r := clr red.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6483
"/            g := clr green.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6484
"/            b := clr blue.
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6485
                rv := (r * scaleRed) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6486
                gv := (g * scaleGreen) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6487
                bv := (b * scaleBlue) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6488
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6489
                v := rv bitShift:redShift.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6490
                v := v bitOr:(gv bitShift:greenShift).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6491
                v := v bitOr:(bv bitShift:blueShift).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6492
                colorValues at:index put:v.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6493
"/ clr print. ' ' print.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6494
"/ rv print. ' ' print. gv print. ' ' print. bv print. ' ' print.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6495
"/ ' -> ' print. v printNL.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6496
7522
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
        ].
2864
dd151bfdff9d care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents: 2832
diff changeset
  6499
    ].
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6500
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6501
    "/ the temporary helper image is only needed to allow
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6502
    "/ the rowAt:putAll: calls below.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6503
1665
e0329f98904d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1664
diff changeset
  6504
    i := (Image implementorForDepth:usedDeviceBitsPerPixel) new.
e0329f98904d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1664
diff changeset
  6505
    i width:width height:height.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
  6506
    i createPixelStore.
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
  6507
    imageBits := i bits.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6508
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6509
    "/ now, walk over the image and replace
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6510
    "/ colorMap indices by color values in the bits array
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6511
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6512
    h := height - 1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6513
    pixelArray := self pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6514
    newPixelArray := i pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6515
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6516
    colorValues notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6517
        0 to:h do:[:y |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6518
            self rowAt:y into:pixelArray.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6519
            1 to:width do:[:x |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6520
                pixel := pixelArray at:x.
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  6521
                newPixelArray at:x put:(colorValues at:pixel + 1 ifAbsent:[0]).
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6522
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6523
            i rowAt:y putAll:newPixelArray.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6524
        ].
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6525
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6526
        0 to:h do:[:y |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6527
            self rowAt:y into:pixelArray.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6528
            1 to:width do:[:x |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6529
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6530
                pixel := pixelArray at:x.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6531
                clr := self colorFromValue:pixel.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6532
                r := clr redByte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6533
                g := clr greenByte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6534
                b := clr blueByte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6535
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6536
                rv := (r * scaleRed) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6537
                gv := (g * scaleGreen) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6538
                bv := (b * scaleBlue) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6539
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6540
                v := rv bitShift:redShift.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6541
                v := v bitOr:(gv bitShift:greenShift).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6542
                v := v bitOr:(bv bitShift:blueShift).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6543
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6544
                newPixelArray at:x put:v.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6545
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6546
            i rowAt:y putAll:newPixelArray.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6547
        ].
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  6548
    ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  6549
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  6550
    form := Form width:width height:height depth:usedDeviceDepth onDevice:aDevice.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6551
    form isNil ifTrue:[^ nil].
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6552
    form initGC.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6553
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6554
    form
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6555
        copyBitsFrom:imageBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6556
        bitsPerPixel:usedDeviceBitsPerPixel
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6557
        depth:usedDeviceDepth
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6558
        padding:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6559
        width:width height:height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6560
        x:0 y:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6561
        toX:0 y:0.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6562
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6563
    ^ form
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6564
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  6565
    "Modified: / 24-07-1998 / 00:56:14 / cg"
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  6566
    "Modified: / 31-01-2017 / 15:01:05 / stefan"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6567
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
  6568
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6569
!Image methodsFor:'converting rgb images'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6570
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6571
asDitheredTrueColor8FormOn:aDevice
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6572
    "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
  6573
     Return the device-form.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  6574
     This method is only valid for trueColor displays."
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6575
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6576
    |fixColors pixel
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6577
     dstIdx     "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6578
     shiftRed   "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6579
     shiftGreen "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6580
     shiftBlue  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6581
     nRed    "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6582
     nGreen  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6583
     nBlue   "{ Class: SmallInteger }"|
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6584
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6585
    shiftRed := aDevice shiftRed.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6586
    shiftGreen := aDevice shiftGreen.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6587
    shiftBlue := aDevice shiftBlue.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6588
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6589
    nRed := 1 bitShift:aDevice bitsRed.
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6590
    nGreen := 1 bitShift:aDevice bitsGreen.
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6591
    nBlue := 1 bitShift:aDevice bitsBlue.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6592
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6593
    fixColors := Array new:(nRed * nGreen * nBlue).
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6594
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6595
    dstIdx := 1.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6596
    0 to:nRed - 1 do:[:sR |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6597
        0 to:nGreen - 1 do:[:sG |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6598
            0 to:nBlue - 1 do:[:sB |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6599
                pixel := (sR bitShift:shiftRed)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6600
                         + (sG bitShift:shiftGreen)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6601
                         + (sB bitShift:shiftBlue).
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6602
                fixColors at:dstIdx put:(Color colorId:pixel).
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6603
                dstIdx := dstIdx + 1
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6604
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6605
        ]
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6606
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6607
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6608
    ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6609
        asFloydSteinbergDitheredDepth8FormOn:aDevice
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6610
        colors:fixColors
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6611
        nRed:nRed nGreen:nGreen nBlue:nBlue
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  6612
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6613
    "Created: / 14-06-1996 / 17:23:52 / cg"
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6614
    "Modified: / 23-06-1997 / 15:22:36 / cg"
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6615
    "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
  6616
!
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6617
5919
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6618
compressColorMap
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6619
    "calculates a new color map for the image, using only used colors"
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6620
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6621
    |depth newColorMap usedColors oldToNew oldBits newBits tmpBits sortBlockForColors|
5919
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6622
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6623
    depth := self depth.
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6624
    usedColors := self realUsedColors.
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6625
    sortBlockForColors := [:a :b |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6626
            a redByte == b redByte ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6627
                a greenByte == b greenByte ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6628
                    a blueByte < b blueByte
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6629
                ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6630
                    a greenByte < b greenByte
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6631
                ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6632
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6633
                a redByte < b redByte
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6634
            ]
5919
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6635
      ].
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6636
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6637
    "/ translation table
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6638
    oldToNew := ByteArray new:(1 bitShift:depth).
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6639
    newColorMap := usedColors asArray.
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6640
    newColorMap sort:sortBlockForColors.
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6641
    self colorMap notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6642
        self colorMap asArray keysAndValuesDo:[:oldIdx :clr |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6643
            |newPixel|
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
            (usedColors includes:clr) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6646
                newPixel := newColorMap indexOf:clr.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6647
                oldToNew at:oldIdx put:newPixel-1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6648
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6649
        ].
5919
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6650
    ].
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6651
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6652
    oldBits := self bits.
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6653
    newBits := ByteArray new:(oldBits size).
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6654
    depth ~~ 8 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6655
        "/ expand/compress can only handle 8bits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6656
        tmpBits := ByteArray uninitializedNew:(self width*self height).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6657
        oldBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6658
            expandPixels:depth
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6659
            width:self width
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6660
            height:self height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6661
            into:tmpBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6662
            mapping:oldToNew.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6663
        tmpBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6664
            compressPixels:depth
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6665
            width:self width
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6666
            height:self height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6667
            into:newBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6668
            mapping:nil
5919
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6669
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6670
        oldBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6671
            expandPixels:depth
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6672
            width:self width
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6673
            height:self height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6674
            into:newBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6675
            mapping:oldToNew.
5919
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6676
    ].
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6677
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6678
    self bits:newBits.
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6679
    self colorMap:newColorMap.
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6680
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6681
    "Created: / 17-07-2012 / 12:13:18 / anwild"
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6682
!
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6683
7282
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6684
copyPixels32AlphaLowTo24From:anImage
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6685
    "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
  6686
     to me as a 24bit non-alpha rgb image"
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6687
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6688
    |imageBits|
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6689
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6690
    imageBits := anImage bits.
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6691
%{
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6692
    OBJ _myBits = __INST(bytes);
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6693
    OBJ w = __INST(width);
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6694
    OBJ h = __INST(height);
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6695
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6696
    if (__isByteArrayLike(_myBits)
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6697
     && __isByteArrayLike(imageBits)
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6698
     && __bothSmallInteger(w, h)) {
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6699
        int _idx;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6700
        int _w = __intVal(w);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6701
        int _h = __intVal(h);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6702
        int _mySize = __byteArraySize(_myBits);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6703
        int _imgSize = __byteArraySize(imageBits);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6704
        char *_myBitsPtr = __ByteArrayInstPtr(_myBits)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6705
        char *_imgBitsPtr = __ByteArrayInstPtr(imageBits)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6706
        char *_myBitsEndPtr = _myBitsPtr + (_w * _h * 3);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6707
        char *_imgBitsEndPtr = _imgBitsPtr + (_w * _h * 4);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6708
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6709
        if ((_w * _h * 3) > _mySize) goto error;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6710
        if ((_w * _h * 4) > _imgSize) goto error;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6711
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6712
        while (_myBitsPtr < _myBitsEndPtr) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6713
            // fetch r,g,b skip a
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6714
            unsigned char _r = _imgBitsPtr[0];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6715
            unsigned char _g = _imgBitsPtr[1];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6716
            unsigned char _b = _imgBitsPtr[2];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6717
            _myBitsPtr[0] = _r;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6718
            _myBitsPtr[1] = _g;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6719
            _myBitsPtr[2] = _b;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6720
            _myBitsPtr += 3;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6721
            _imgBitsPtr += 4;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6722
        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6723
        RETURN( self );
7282
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6724
    }
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6725
error: ;
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6726
    console_printf("Image: oops - bits-size in copyPixels32\n");
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6727
%}.
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6728
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6729
    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
  6730
        |a r g b rgbPixel|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6731
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6732
        "/ bgra-pixel
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6733
        "/ a := pixel bitAnd:16rFF.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6734
        r := (pixel bitShift:-8) bitAnd:16rFF.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6735
        g := (pixel bitShift:-16) bitAnd:16rFF.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6736
        b := (pixel bitShift:-24) bitAnd:16rFF.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6737
        rgbPixel := r + (g bitShift:8) + (b bitShift:16).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6738
        self pixelAtX:x y:y put:rgbPixel
7282
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6739
    ].
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6740
!
8b3434078110 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 7277
diff changeset
  6741
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6742
rgbImageAsFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6743
    "convert am rgb image to a device-form on aDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6744
     Return the device-form."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6745
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6746
    |visual|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6747
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6748
    visual := aDevice visualType.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6749
    (visual == #StaticGray) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6750
        ^ self asGrayFormOn:aDevice
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6751
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6752
    (visual == #TrueColor) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6753
        ^ self rgbImageAsTrueColorFormOn:aDevice
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6754
    ].
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6755
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6756
    "/ PseudoColor conversion also works for StaticColor, GrayScale
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6757
    "/ and DirectColor displays; although possibly with suboptimal results
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6758
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6759
    ^ self rgbImageAsPseudoFormOn:aDevice
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6760
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6761
    "Modified: 14.6.1996 / 19:30:06 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6762
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6763
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6764
rgbImageAsPseudoFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6765
    "return a pseudocolor form from the rgb-picture"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6766
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6767
    |n     "{ Class: SmallInteger }"
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6768
     depth "{ Class: SmallInteger }"
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6769
     palette f|
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6770
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6771
    (depth := self depth) <= 8 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6772
        "/ simulate it via a temporary palette image
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6773
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6774
        palette := Array new:(1 bitShift:depth).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6775
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6776
        n := (1 bitShift:depth)-1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6777
        0 to:n do:[:pixelValue |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6778
            palette at:(pixelValue+1) put:(self colorFromValue:pixelValue)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6779
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6780
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6781
        self setColorMap:palette.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6782
        photometric := #palette.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6783
        f := self paletteImageAsPseudoFormOn:aDevice.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6784
        self setColorMap:nil.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6785
        photometric := #rgb.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6786
        ^ f
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6787
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6788
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6789
    ^ self subclassResponsibility
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6790
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6791
    "Modified: 8.6.1996 / 10:58:25 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6792
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6793
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6794
rgbImageAsTrueColorFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6795
    "return a truecolor form from the rgb-picture."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6796
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  6797
    |bestFormat usedDeviceDepth usedDeviceBitsPerPixel
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6798
     form|
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6799
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6800
    bestFormat := self bestSupportedImageFormatFor:aDevice.
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  6801
    usedDeviceDepth := bestFormat at:#depth.
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  6802
    usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6803
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6804
    "/ 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
  6805
    usedDeviceBitsPerPixel == 15 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6806
        usedDeviceBitsPerPixel := 16
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  6807
    ].
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  6808
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6809
    "/
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6810
    "/ only the trivial case, where the depths match
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6811
    "/ is handled here; conversions are supposed to
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6812
    "/ be done in concrete subclasses (see D24Image)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6813
    "/
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6814
    self bitsPerPixel == usedDeviceBitsPerPixel ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6815
        "/ kludge - convert to a deep image first, then to a form.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6816
        ^ ((Image implementorForDepth:usedDeviceBitsPerPixel) fromImage:self) asFormOn:aDevice
5126
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  6817
"/        '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
  6818
"/        ^ self asMonochromeFormOn:aDevice
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  6819
    ].
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  6820
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  6821
    form := Form width:width height:height depth:usedDeviceDepth onDevice:aDevice.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6822
    form isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6823
        'Image [warning]: display bitmap creation failed' errorPrintCR.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6824
        ^ nil
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6825
    ].
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6826
    form initGC.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6827
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6828
    form
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6829
        copyBitsFrom:self bits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6830
        bitsPerPixel:usedDeviceBitsPerPixel
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6831
        depth:usedDeviceDepth
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6832
        padding:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6833
        width:width height:height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6834
        x:0 y:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6835
        toX:0 y:0.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6836
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6837
    ^ form
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6838
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  6839
    "Modified: / 27-05-2007 / 13:44:26 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6840
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6841
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6842
!Image methodsFor:'copying'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6843
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6844
postCopy
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  6845
    "redefined to also copy the pixels and the colorMap
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  6846
     and clear out any device handles in the copy."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  6847
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6848
    bytes := bytes copy.
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6849
    colorMap isColormap ifTrue:[
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6850
        colorMap := colorMap copy.
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6851
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6852
        colorMap := MappedPalette withColors:colorMap.
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  6853
    ].
1963
ab2d96e4e140 care for masks in copy/copySubImage;
tz
parents: 1962
diff changeset
  6854
    device := deviceForm := monoDeviceForm := fullColorDeviceForm := nil.
ab2d96e4e140 care for masks in copy/copySubImage;
tz
parents: 1962
diff changeset
  6855
    mask := mask copy.
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  6856
    maskedPixelsAre0 := false.
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  6857
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6858
    "Modified: / 22-08-1998 / 11:27:09 / cg"
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  6859
    "Modified: / 30-01-2017 / 19:16:02 / stefan"
2947
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6860
!
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6861
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6862
skipInstvarIndexInDeepCopy:index
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6863
    "a helper for deepCopy; only indices for which this method returns
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6864
     false are copied in a deep copy."
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6865
7494
70c399ea367b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7484
diff changeset
  6866
    "
70c399ea367b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7484
diff changeset
  6867
        self allInstanceVariableNames indexOf:#device
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  6868
        self allInstanceVariableNames indexOf:#deviceForm
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  6869
        self allInstanceVariableNames indexOf:#monoDeviceForm
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  6870
        self allInstanceVariableNames indexOf:#fullColorDeviceForm
7494
70c399ea367b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7484
diff changeset
  6871
    "
70c399ea367b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7484
diff changeset
  6872
70c399ea367b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7484
diff changeset
  6873
    index == 13 ifTrue:[
70c399ea367b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7484
diff changeset
  6874
        ^ true "/ skip device
70c399ea367b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7484
diff changeset
  6875
    ].
70c399ea367b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7484
diff changeset
  6876
    index == 14 ifTrue:[
70c399ea367b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7484
diff changeset
  6877
        ^ true "/ skip deviceForm
70c399ea367b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7484
diff changeset
  6878
    ].
70c399ea367b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7484
diff changeset
  6879
    index == 15 ifTrue:[
70c399ea367b #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7484
diff changeset
  6880
        ^ true "/ skip monoDeviceForm
2947
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6881
    ].
7573
656c59bc93ad #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7565
diff changeset
  6882
    index == 16 ifTrue:[
656c59bc93ad #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7565
diff changeset
  6883
        ^ true "/ skip fullColorDeviceForm
656c59bc93ad #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7565
diff changeset
  6884
    ].
2947
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6885
    ^ false
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  6886
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
  6887
    "Modified (comment): / 31-01-2017 / 15:41:40 / stefan"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6888
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6889
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6890
!Image methodsFor:'displaying'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6891
1737
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  6892
asImage
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  6893
    "ST-80 compatibility
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  6894
    "
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  6895
    ^ self
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  6896
!
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  6897
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6898
displayFilledOn:aGC
759
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  6899
    "display the receiver as an opaque image.
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6900
     This allows Images to be wrapped by a FillingWrapper"
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6901
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6902
    aGC displayOpaqueForm:self x:0 y:0.
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6903
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6904
    "Created: 29.5.1996 / 10:34:18 / cg"
759
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  6905
    "Modified: 29.5.1996 / 10:52:36 / cg"
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6906
!
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6907
3865
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6908
displayOn:aGC x:x y:y
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6909
    "draw the receiver in the graphicsContext, aGC.
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6910
     Smalltalk-80 compatibility"
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6911
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6912
    aGC displayForm:self x:x y:y.
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6913
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6914
    "Modified: 23.4.1996 / 11:12:31 / cg"
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6915
    "Created: 12.5.1996 / 20:14:31 / cg"
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6916
!
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6917
3729
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6918
displayOn:aGC x:x y:y opaque:opaque
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6919
    "draw the receiver in the graphicsContext, aGC.
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6920
     Smalltalk-80 compatibility"
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6921
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6922
    opaque ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6923
        self displayOpaqueOn:aGC x:x y:y .
3729
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6924
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6925
        self displayOn:aGC x:x y:y .
3729
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6926
    ].
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6927
!
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6928
3379
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6929
displayOpaqueOn:aGC at:aPoint
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6930
    "draw the receiver in the graphicsContext, aGC.
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6931
     Smalltalk-80 compatibility"
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6932
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6933
    self displayOpaqueOn:aGC x:aPoint x y:aPoint y.
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6934
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6935
    "Modified: 12.5.1996 / 20:16:38 / cg"
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6936
!
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6937
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6938
displayOpaqueOn:aGC x:x y:y
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6939
    "draw the receiver in the graphicsContext, aGC.
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6940
     Smalltalk-80 compatibility"
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6941
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6942
    aGC displayOpaqueForm:self x:x y:y.
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6943
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6944
    "Modified: 23.4.1996 / 11:12:31 / cg"
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6945
    "Created: 22.10.1996 / 16:35:49 / cg"
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6946
!
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6947
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6948
displayStrokedOn:aGC
759
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  6949
    "display the receiver as an non opaque image.
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6950
     This allows Images to be wrapped by a StrokingWrapper"
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6951
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6952
    aGC displayForm:self x:0 y:0.
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6953
759
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  6954
    "Created: 29.5.1996 / 10:34:18 / cg"
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  6955
    "Modified: 29.5.1996 / 10:52:30 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6956
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6957
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6958
!Image methodsFor:'dither helpers'!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6959
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6960
burkesDitheredMonochromeBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6961
    "return the bitmap for a dithered monochrome bitmap from the image.
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6962
     Works for any source depths / photometric.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6963
     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
  6964
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6965
    |dstIndex        "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6966
     nextDst         "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6967
     bytesPerMonoRow "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6968
     monoBits greyValues
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6969
     errorArray
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6970
     errorArray1
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6971
     e t
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6972
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6973
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6974
     bitCnt          "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6975
     byte            "{Class: SmallInteger }"
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  6976
     grey|
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6977
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6978
    self depth > 12 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6979
        ^ self floydSteinbergDitheredMonochromeBits
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6980
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6981
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6982
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6983
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6984
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6985
    bytesPerMonoRow := (w + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6986
    monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6987
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6988
    errorArray := Array new:(w+4).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6989
    errorArray1 := Array new:(w+4) withAll:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6990
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6991
    dstIndex := 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6992
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6993
    "/ 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
  6994
    "/ use table-value in loop
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6995
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6996
    greyValues := self greyMapForRange:(255*1024).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6997
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6998
    0 to:(h-1) do:[:y |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  6999
        nextDst := dstIndex + bytesPerMonoRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7000
        byte := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7001
        bitCnt := 8.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7002
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7003
        t := errorArray.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7004
        errorArray := errorArray1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7005
        errorArray1 := t.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7006
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7007
        errorArray1 atAllPut:0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7008
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7009
        self valuesAtY:y from:0 to:(w-1) do:[:x :pixel |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7010
            |eP "{Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7011
             eD
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7012
             eI "{Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7013
             xE "{Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7014
             xN "{Class: SmallInteger }" |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7015
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7016
            "/ get the colors grey value [0 .. 1]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7017
            grey := greyValues at:(pixel + 1).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7018
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7019
            "/ adjust error
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7020
            xE := x + 2 + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7021
            grey := (grey + (errorArray at:xE)).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7022
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7023
            byte := byte bitShift:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7024
            grey > (127*1024) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7025
                byte := byte bitOr:1.      "/ white
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7026
                e := grey - (255*1024)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7027
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7028
                e := grey                  "/ black
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7029
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7030
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7031
            e ~= 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7032
                "/ distribute the error:
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7033
                "/                  XX  8  4
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7034
                "/             2  4  8  4  2
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7035
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7036
                eD := e.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7037
                eI := e // 32.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7038
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7039
                eP := eI * 8. eD := eD - eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7040
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7041
                xN := xE + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7042
                errorArray at:xN put:(errorArray at:xN) + eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7043
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7044
                eD := eD - eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7045
                errorArray1 at:xE put:(errorArray1 at:xE) + eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7046
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7047
                eP := eI * 4. eD := eD - eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7048
                xN := xE + 2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7049
                errorArray at:xN put:(errorArray at:xN) + eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7050
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7051
                eD := eD - eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7052
                xN := xE - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7053
                errorArray1 at:xN put:(errorArray1 at:xN) + eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7054
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7055
                eD := eD - eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7056
                xN := xE + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7057
                errorArray1 at:xN put:(errorArray1 at:xN) + eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7058
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7059
                eP := eI * 2. eD := eD - eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7060
                xN := xE - 2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7061
                errorArray1 at:xN put:(errorArray1 at:xN) + eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7062
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7063
                "/ eD := eD.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7064
                xN := xE + 2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7065
                errorArray1 at:xN put:(errorArray1 at:xN) + eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7066
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7067
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7068
            bitCnt := bitCnt - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7069
            bitCnt == 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7070
                monoBits at:dstIndex put:byte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7071
                dstIndex := dstIndex + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7072
                byte := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7073
                bitCnt := 8.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7074
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7075
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7076
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7077
        bitCnt ~~ 8 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7078
            byte := byte bitShift:bitCnt.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7079
            monoBits at:dstIndex put:byte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7080
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7081
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7082
        dstIndex := nextDst.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7083
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7084
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7085
    ^ monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7086
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7087
    "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
  7088
    "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
  7089
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7090
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  7091
floydSteinbergDitheredDepth8BitsColors:colors
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  7092
    "return a floyd-steinberg dithered bitmap from the receiver picture,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7093
     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
  7094
     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
  7095
     (which need not be a colorCubes colors)."
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  7096
3157
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  7097
    ^ self floydSteinbergDitheredDepth8BitsColors:colors map:nil
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  7098
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  7099
!
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  7100
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  7101
floydSteinbergDitheredDepth8BitsColors:colors map:aMapOrNil
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7102
    "return a floyd-steinberg dithered bitmap from the receiver picture,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7103
     which must be a depth-24 image.
3157
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  7104
     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
  7105
     (which need not be a colorCubes colors)."
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  7106
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7107
    |pseudoBits
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7108
     ditherRGBBytes ditherColors
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7109
     w       "{Class: SmallInteger }"
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7110
     h       "{Class: SmallInteger }"
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7111
     index   "{Class: SmallInteger }"
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  7112
     lookupPos "{Class: SmallInteger }"
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7113
     ditherIds failed lastColor qScramble
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  7114
     clrLookup error clr|
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7115
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7116
    self depth ~~ 24 ifTrue:[^ nil].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7117
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7118
    "/ collect valid ditherColors ...
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7119
    aMapOrNil isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7120
        ditherColors := colors select:[:clr | clr notNil].
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7121
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7122
        ditherColors := colors
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7123
    ].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7124
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7125
    "/ ... and sort by manhatten distance from black
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7126
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7127
    qScramble := #(
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7128
                "/  2rX00X00X00X00
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7129
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7130
                    2r000000000000    "/ 0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7131
                    2r000000000100    "/ 1
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7132
                    2r000000100000    "/ 2
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7133
                    2r000000100100    "/ 3
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7134
                    2r000100000000    "/ 4
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7135
                    2r000100000100    "/ 5
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7136
                    2r000100100000    "/ 6
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7137
                    2r000100100100    "/ 7
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7138
                    2r100000000000    "/ 8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7139
                    2r100000000100    "/ 9
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7140
                    2r100000100000    "/ a
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7141
                    2r100000100100    "/ b
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7142
                    2r100100000000    "/ c
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7143
                    2r100100000100    "/ d
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7144
                    2r100100100000    "/ e
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7145
                    2r100100100100    "/ f
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7146
                  ).
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7147
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7148
    ditherColors := ditherColors sort:[:a :b |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7149
                                |cr "{Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7150
                                 cg "{Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7151
                                 cb "{Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7152
                                 i1 "{Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7153
                                 i2 "{Class: SmallInteger }"|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7154
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7155
                                cr := a redByte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7156
                                cg := a greenByte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7157
                                cb := a blueByte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7158
                                i1 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7159
                                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
  7160
                                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
  7161
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7162
                                cr := b redByte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7163
                                cg := b greenByte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7164
                                cb := b blueByte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7165
                                i2 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7166
                                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
  7167
                                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
  7168
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7169
                                i1 < i2
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7170
                    ].
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7171
    aMapOrNil isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7172
        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
  7173
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7174
        ditherIds := aMapOrNil asByteArray
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7175
    ].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7176
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7177
    "/ 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
  7178
    "/ to the position in the colorList
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7179
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7180
    clrLookup := ByteArray new:(4096).
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7181
    index := 0.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7182
    ditherColors keysAndValuesDo:[:clrPosition :clr |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7183
        |r g b i|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7184
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7185
        r := clr redByte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7186
        g := clr greenByte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7187
        b := clr blueByte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7188
        i := qScramble at:((r bitShift:-4) bitAnd:16r0F) + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7189
        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
  7190
        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
  7191
        lookupPos := i.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7192
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  7193
        index+1 to:lookupPos do:[:idx|
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  7194
            clrLookup at:idx put:(clrPosition-1-1).
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  7195
        ].
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  7196
        index := lookupPos.
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7197
    ].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7198
    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
  7199
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7200
"/    [index <= (4095)] whileTrue:[
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7201
"/        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
  7202
"/        index := index + 1.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7203
"/    ].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7204
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7205
    "/ collect ditherColor components
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7206
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7207
    lastColor := ditherColors size.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7208
    ditherIds := ByteArray uninitializedNew:lastColor.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7209
    ditherRGBBytes := ByteArray uninitializedNew:(lastColor * 3).
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7210
    index := 1.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7211
    1 to:lastColor do:[:pix |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7212
        clr := ditherColors at:pix.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7213
        ditherRGBBytes at:index put:(clr redByte).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7214
        ditherRGBBytes at:index+1 put:(clr greenByte).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7215
        ditherRGBBytes at:index+2 put:(clr blueByte).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7216
        aMapOrNil isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7217
            ditherIds at:pix put:clr colorId.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7218
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7219
            ditherIds at:pix put:(aMapOrNil at:pix).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7220
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7221
        index := index + 3.
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7222
    ].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7223
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7224
    pseudoBits := ByteArray uninitializedNew:(width * height).
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
    w := width + 2.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7227
    error := ByteArray uninitializedNew:w*(3*2).
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7228
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7229
    w := width.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7230
    h := height.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7231
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7232
    failed := true.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7233
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7234
%{
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7235
    int __x, __y;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7236
    int __eR, __eG, __eB;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7237
    unsigned char *srcP, *dstP;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7238
    unsigned char *idP;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7239
    unsigned char *dp;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7240
    unsigned char *__clrLookup;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7241
    short *errP, *eP;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7242
    int __fR, __fG, __fB;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7243
    int iR, iG, iB;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7244
    int idx;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7245
    int __w = __intVal(w);
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7246
    int __h = __intVal(h);
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7247
    int __nColors = __intVal(lastColor);
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7248
    int __wR = -1, __wG, __wB;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7249
    static int __qScramble[16] = {
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7250
                    0x000 /* 2r000000000000    0 */,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7251
                    0x004 /* 2r000000000100    1 */,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7252
                    0x020 /* 2r000000100000    2 */,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7253
                    0x024 /* 2r000000100100    3 */,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7254
                    0x100 /* 2r000100000000    4 */,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7255
                    0x104 /* 2r000100000100    5 */,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7256
                    0x120 /* 2r000100100000    6 */,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7257
                    0x124 /* 2r000100100100    7 */,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7258
                    0x800 /* 2r100000000000    8 */,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7259
                    0x804 /* 2r100000000100    9 */,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7260
                    0x820 /* 2r100000100000    a */,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7261
                    0x824 /* 2r100000100100    b */,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7262
                    0x900 /* 2r100100000000    c */,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7263
                    0x904 /* 2r100100000100    d */,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7264
                    0x920 /* 2r100100100000    e */,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7265
                    0x924 /* 2r100100100100    f */,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7266
                  };
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7267
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7268
    if (__isByteArrayLike(__INST(bytes))
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7269
     && __isByteArray(pseudoBits)
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7270
     && __isByteArray(ditherRGBBytes)
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7271
     && __isByteArray(ditherIds)
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7272
     && __isByteArray(clrLookup)
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7273
     && __isByteArray(error)) {
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7274
        failed = false;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7275
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7276
        srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7277
        dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7278
        idP = __ByteArrayInstPtr(ditherIds)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7279
        __clrLookup = __ByteArrayInstPtr(clrLookup)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7280
        errP = (short *) __ByteArrayInstPtr(error)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7281
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7282
        /*
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7283
         * clear error accumulator
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7284
         */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7285
        eP = errP;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7286
        bzero(eP, (__w+2) * 2 * 3);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7287
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7288
        for (__y=__h; __y>0; __y--) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7289
            __eR = __eG = __eB = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7290
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7291
            eP = &(errP[3]);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7292
            __eR = eP[0];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7293
            __eG = eP[1];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7294
            __eB = eP[2];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7295
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7296
            for (__x=__w; __x>0; __x--) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7297
                int __want;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7298
                int pix;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7299
                int __wantR, __wantG, __wantB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7300
                int idx;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7301
                int tR, tG, tB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7302
                int nR, nG, nB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7303
                int dR, dG, dB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7304
                int minDelta, bestIdx;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7305
                int cnt;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7306
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7307
                __wantR = *srcP++;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7308
                __wantG = *srcP++;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7309
                __wantB = *srcP++;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7310
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7311
                /*
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7312
                 * wR, wG and wB is the wanted r/g/b value;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7313
                 */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7314
                __wantR = __wantR + __eR;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7315
                __wantG = __wantG + __eG;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7316
                __wantB = __wantB + __eB;
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7317
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7318
#define RED_SCALE 30
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7319
#define GREEN_SCALE 59
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7320
#define BLUE_SCALE 11
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7321
#define GOOD_DELTA 30
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7322
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7323
#define xRED_SCALE 1
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7324
#define xGREEN_SCALE 1
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7325
#define xBLUE_SCALE 1
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7326
#define xGOOD_DELTA 3
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7327
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7328
#define FAST_LOOKUP
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7329
/* #define ONE_SHOT */
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7330
#define NPROBE 8
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7331
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7332
#ifndef FAST_LOOKUP
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7333
                if ((__wantR == __wR)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7334
                 && (__wantG == __wG)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7335
                 && (__wantB == __wB)) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7336
                    /*
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7337
                     * same color again - reuse last bestMatch
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7338
                     */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7339
                } else
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7340
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7341
                {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7342
                    __wR = __wantR;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7343
                    __wG = __wantG;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7344
                    __wB = __wantB;
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7345
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7346
#ifdef FAST_LOOKUP
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7347
                    if(__wR > 255) __wR = 255;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7348
                    else if (__wR < 0) __wR = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7349
                    if(__wG > 255) __wG = 255;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7350
                    else if (__wG < 0) __wG = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7351
                    if(__wB > 255) __wB = 255;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7352
                    else if (__wB < 0) __wB = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7353
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7354
                    {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7355
                        int lookupIndex;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7356
                        int idx, idx0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7357
                        int d, delta;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7358
                        unsigned char *dp0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7359
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7360
                        dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7361
                        lookupIndex =    __qScramble[((__wR & 0xF0)>>4)];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7362
                        lookupIndex |=   __qScramble[((__wG & 0xF0)>>4)] >> 1;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7363
                        lookupIndex |=   __qScramble[((__wB & 0xF0)>>4)] >> 2;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7364
                        idx = bestIdx =__clrLookup[lookupIndex];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7365
                        dp += (idx+idx+idx);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7366
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7367
                        /* try color at lookupIndex */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7368
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7369
                        d = dp[0];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7370
                        delta = (__wR - d) * RED_SCALE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7371
                        if (delta < 0) delta = -delta;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7372
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7373
                        d = dp[1];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7374
                        if (__wG > d)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7375
                            delta += (__wG - d) * GREEN_SCALE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7376
                        else
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7377
                            delta += (d - __wG) * GREEN_SCALE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7378
                        d = dp[2];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7379
                        if (__wB > d)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7380
                            delta += (__wB - d) * BLUE_SCALE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7381
                        else
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7382
                            delta += (d - __wB) * BLUE_SCALE;
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
                        if (delta <= GOOD_DELTA) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7385
                            goto foundBest;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7386
                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7387
                        minDelta = delta;
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7388
# ifndef ONE_SHOT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7389
                        idx0 = idx; dp0 = dp;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7390
                        cnt = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7391
                        while ((++cnt <= NPROBE) && (idx > 0)) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7392
                            /* try previous color(s) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7393
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7394
                            idx--; dp -= 3;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7395
                            d = dp[0];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7396
                            delta = (__wR - d) * RED_SCALE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7397
                            if (delta < 0) delta = -delta;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7398
                            d = dp[1];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7399
                            if (__wG > d)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7400
                                delta += (__wG - d) * GREEN_SCALE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7401
                            else
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7402
                                delta += (d - __wG) * GREEN_SCALE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7403
                            d = dp[2];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7404
                            if (__wB > d)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7405
                                delta += (__wB - d) * BLUE_SCALE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7406
                            else
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7407
                                delta += (d - __wB) * BLUE_SCALE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7408
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7409
                            if (delta < minDelta) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7410
                                bestIdx = idx;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7411
                                if (delta <= GOOD_DELTA) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7412
                                    goto foundBest;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7413
                                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7414
                                minDelta = delta;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7415
                            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7416
                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7417
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7418
                        idx = idx0; dp = dp0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7419
                        cnt = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7420
                        while ((++cnt <= NPROBE) && (++idx < __nColors)) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7421
                            /* try next color */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7422
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7423
                            dp += 3;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7424
                            d = dp[0];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7425
                            delta = (__wR - d) * RED_SCALE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7426
                            if (delta < 0) delta = -delta;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7427
                            d = dp[1];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7428
                            if (__wG > d)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7429
                                delta += (__wG - d) * GREEN_SCALE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7430
                            else
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7431
                                delta += (d - __wG) * GREEN_SCALE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7432
                            d = dp[2];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7433
                            if (__wB > d)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7434
                                delta += (__wB - d) * BLUE_SCALE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7435
                            else
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7436
                                delta += (d - __wB) * BLUE_SCALE;
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
                            if (delta < minDelta) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7439
                                bestIdx = idx;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7440
                                if (delta <= GOOD_DELTA) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7441
                                    goto foundBest;
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
                                minDelta = delta;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7444
                            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7445
                        }
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7446
# endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7447
                    }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7448
        foundBest: ;
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7449
#else
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7450
/*
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7451
                    if(__wR > 255) __wR = 255;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7452
                    else if (__wR < 0) __wR = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7453
                    if(__wG > 255) __wG = 255;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7454
                    else if (__wG < 0) __wG = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7455
                    if(__wB > 255) __wB = 255;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7456
                    else if (__wB < 0) __wB = 0;
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7457
*/
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7458
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7459
                    /* find the best matching color */
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
                    minDelta = 99999;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7462
                    bestIdx = -1;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7463
                    dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7464
                    for (idx = 0; idx<__nColors; idx++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7465
                        int d, delta;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7466
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7467
                        d = dp[0];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7468
                        delta = (__wR - d) * RED_SCALE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7469
                        if (delta < 0) delta = -delta;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7470
                        if (delta < minDelta) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7471
                            d = dp[1];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7472
                            if (__wG > d)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7473
                                delta += (__wG - d) * GREEN_SCALE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7474
                            else
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7475
                                delta += (d - __wG) * GREEN_SCALE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7476
                            if (delta < minDelta) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7477
                                d = dp[2];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7478
                                if (__wB > d)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7479
                                    delta += (__wB - d) * BLUE_SCALE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7480
                                else
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7481
                                    delta += (d - __wB) * BLUE_SCALE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7482
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7483
                                if (delta < minDelta) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7484
                                    bestIdx = idx;
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
                                        break;
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;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7489
                                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7490
                            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7491
                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7492
                        dp += 3;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7493
                    }
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7494
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7495
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7496
                dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7497
                dp += bestIdx * 3;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7498
                dR = dp[0];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7499
                dG = dp[1];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7500
                dB = dp[2];
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7501
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7502
/*
4725
c8896df7bd3f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4717
diff changeset
  7503
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
  7504
                __wantR, __wantG, __wantB,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7505
                __wR, __wG, __wB,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7506
                dR, dG, dB);
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7507
*/
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7508
                /*
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7509
                 * store the corresponding dither colors colorId
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7510
                 */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7511
                *dstP++ = idP[bestIdx];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7512
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7513
                /*
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7514
                 * the new error & distribute the error
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7515
                 */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7516
                __eR = __wantR - dR;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7517
                if (__eR) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7518
                    tR = __eR >> 4;  /* 16th of error */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7519
                    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
  7520
                    eP[0] = tR*5;         /* 5/16th for (x / y+1) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7521
                    eP[-3] = tR*3;        /* 3/16th for (x-1 / y+1) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7522
                    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
  7523
                    __eR = nR;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7524
                } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7525
                    __eR = eP[3];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7526
                    eP[0] = eP[-3] = eP[3] = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7527
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7528
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7529
                __eG = __wantG - dG;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7530
                if (__eG) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7531
                    tG = __eG >> 4;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7532
                    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
  7533
                    eP[1] = tG*5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7534
                    eP[-2] = tG*3;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7535
                    eP[4] = __eG - (tG*15);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7536
                    __eG = nG;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7537
                } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7538
                    __eG = eP[4];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7539
                    eP[1] = eP[-2] = eP[4] = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7540
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7541
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7542
                __eB = __wantB - dB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7543
                if (__eB) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7544
                    tB = __eB >> 4;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7545
                    nB = eP[5] + (tB * 7);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7546
                    eP[2] = tB*5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7547
                    eP[-1] = tB*3;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7548
                    eP[5] = __eB - (tB*15);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7549
                    __eB = nB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7550
                } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7551
                    __eB = eP[5];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7552
                    eP[2] = eP[-1] = eP[5] = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7553
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7554
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7555
                eP += 3;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7556
            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7557
        }
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
%}.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7560
    failed ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7561
        self primitiveFailed.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7562
        ^ nil
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7563
    ].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7564
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7565
    ^ pseudoBits
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  7566
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
  7567
    "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
  7568
!
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  7569
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7570
floydSteinbergDitheredDepth8BitsColors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  7571
    "return a floyd-steinberg dithered bitmap from the receiver picture,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7572
     which must be a depth-8 image.
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  7573
     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
  7574
     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
  7575
     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
  7576
     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
  7577
     Color class.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7578
     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
  7579
     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
  7580
     for example to create dithered Depth4Images from Depth8Images."
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7581
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7582
    |pseudoBits
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7583
     rgbBytes
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7584
     w       "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7585
     h       "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7586
     index   "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7587
     fixR    "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7588
     fixG    "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7589
     fixB    "{Class: SmallInteger }"
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7590
     fixGfixB
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7591
     fixIds failed map lastColor
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7592
     rgbIDX  "{Class: SmallInteger }"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7593
     idxAndErrRBytes idxAndErrGBytes idxAndErrBBytes
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7594
     error clr|
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7595
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  7596
    self depth ~~ 8 ifTrue:[^ nil].
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  7597
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7598
    fixR := nRed.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7599
    fixR == 0 ifTrue:[ ^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7600
    fixG := nGreen.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7601
    fixG == 0 ifTrue:[ ^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7602
    fixB := nBlue.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7603
    fixB == 0 ifTrue:[ ^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7604
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7605
    "/ simple check
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7606
    (fixR * fixG * fixB) ~~ fixColors size ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7607
        self error:'invalid color array passed'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7608
        ^ nil
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7609
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7610
    fixIds := (fixColors asArray collect:[:clr | clr colorId]) asByteArray.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7611
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7612
    "/
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7613
    "/ collect color components as integer values (for integer arithmetic)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7614
    "/
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7615
    rgbBytes := ByteArray uninitializedNew:256 * 3.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7616
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7617
    index := 1.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7618
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7619
    photometric == #palette ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7620
        lastColor := colorMap size - 1
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7621
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7622
        lastColor := 255.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7623
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7624
    0 to:lastColor do:[:pix |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7625
        clr := self colorFromValue:pix.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7626
        rgbBytes at:index put:(clr redByte).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7627
        rgbBytes at:index+1 put:(clr greenByte).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7628
        rgbBytes at:index+2 put:(clr blueByte).
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
        index := index + 3.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7631
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7632
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7633
    pseudoBits := ByteArray uninitializedNew:(width * height).
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7634
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7635
    w := width + 2.
1636
c30f6644666e dont use bcopy in #floydSteinbergDitheredDepth8BitsColors
Claus Gittinger <cg@exept.de>
parents: 1630
diff changeset
  7636
    error := ByteArray new:w*(3*2).
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7637
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7638
    w := width.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7639
    h := height.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7640
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7641
    idxAndErrRBytes := ByteArray uninitializedNew:256*2.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7642
    idxAndErrGBytes := ByteArray uninitializedNew:256*2.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7643
    idxAndErrBBytes := ByteArray uninitializedNew:256*2.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7644
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7645
    fixGfixB := fixG * fixB.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7646
    index := 1.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7647
    0 to:255 do:[:i |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7648
        rgbIDX := (i * (fixR-1) + 128) // 255. "red index rounded"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7649
        idxAndErrRBytes at:index put:(rgbIDX * fixGfixB).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7650
        idxAndErrRBytes at:index+1 put:i - (rgbIDX * 255 // (fixR-1)) + 128.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7651
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7652
        rgbIDX := (i * (fixG-1) + 128) // 255. "green index rounded"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7653
        idxAndErrGBytes at:index put:(rgbIDX * fixB).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7654
        idxAndErrGBytes at:index+1 put:i - (rgbIDX * 255 // (fixG-1)) + 128.
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
        rgbIDX := (i * (fixB-1) + 128) // 255. "blue index rounded"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7657
        idxAndErrBBytes at:index put:(rgbIDX ).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7658
        idxAndErrBBytes at:index+1 put:i - (rgbIDX * 255 // (fixB-1)) + 128.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7659
        index := index + 2.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7660
    ].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7661
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7662
    failed := true.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7663
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7664
%{
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7665
    int __x, __y;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7666
    int __eR, __eG, __eB;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7667
    unsigned char *srcP, *dstP;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7668
    unsigned char *rgbP;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7669
    unsigned char *idP;
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7670
    unsigned char *__idxAndErrRBytes, *__idxAndErrGBytes, *__idxAndErrBBytes;
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7671
    short *errP, *eP;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7672
    int idx;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7673
    int __w = __intVal(w);
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7674
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7675
    if (__isByteArrayLike(__INST(bytes))
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7676
     && __isByteArray(pseudoBits)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7677
     && __isByteArray(rgbBytes)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7678
     && __isByteArray(fixIds)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7679
     && __isByteArray(error)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7680
     && __bothSmallInteger(fixR, fixG)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7681
     && __isSmallInteger(fixB)) {
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7682
        failed = false;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7683
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7684
        srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7685
        dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7686
        rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7687
        idP = __ByteArrayInstPtr(fixIds)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7688
        __idxAndErrRBytes = __ByteArrayInstPtr(idxAndErrRBytes)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7689
        __idxAndErrGBytes = __ByteArrayInstPtr(idxAndErrGBytes)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7690
        __idxAndErrBBytes = __ByteArrayInstPtr(idxAndErrBBytes)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7691
        errP = (short *) __ByteArrayInstPtr(error)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7692
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7693
        eP = errP;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7694
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7695
        for (__y=__intVal(h); __y>0; __y--) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7696
            __eR = __eG = __eB = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7697
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7698
            eP = &(errP[3]);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7699
            __eR = eP[0];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7700
            __eG = eP[1];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7701
            __eB = eP[2];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7702
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7703
            for (__x=__w; __x>0; __x--) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7704
                int __want;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7705
                int pix;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7706
                int idx;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7707
                int tR, tG, tB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7708
                int nR, nG, nB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7709
                int iRGB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7710
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7711
                pix = *srcP++;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7712
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7713
                /*
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7714
                 * wR, wG and wB is the wanted r/g/b value;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7715
                 */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7716
                pix = pix+pix+pix;  /* pix * 3 */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7717
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7718
                /*
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7719
                 * compute indexR/G/B and the new error:
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7720
                 */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7721
                __want = rgbP[pix]   + __eR;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7722
                if (__want > 255) __want = 255;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7723
                else if (__want < 0) __want = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7724
                __want += __want;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7725
                idx = __idxAndErrRBytes[__want];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7726
                __eR = __idxAndErrRBytes[__want+1];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7727
                __eR -= 128;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7728
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7729
                __want = rgbP[pix+1] + __eG;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7730
                if (__want > 255) __want = 255;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7731
                else if (__want < 0) __want = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7732
                __want += __want;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7733
                idx += __idxAndErrGBytes[__want];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7734
                __eG = __idxAndErrGBytes[__want+1];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7735
                __eG -= 128;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7736
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7737
                __want = rgbP[pix+2] + __eB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7738
                if (__want > 255) __want = 255;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7739
                else if (__want < 0) __want = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7740
                __want += __want;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7741
                idx += __idxAndErrBBytes[__want];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7742
                __eB = __idxAndErrBBytes[__want+1];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7743
                __eB -= 128;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7744
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7745
                /*
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7746
                 * store the corresponding dither colors colorId
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7747
                 */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7748
                *dstP++ = idP[idx];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7749
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7750
                /*
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7751
                 * distribute the error
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
                if (__eR) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7754
                    tR = __eR >> 4;  /* 16th of error */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7755
                    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
  7756
                    eP[0] = tR*5;         /* 5/16th for (x / y+1) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7757
                    eP[-3] = tR*3;        /* 3/16th for (x-1 / y+1) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7758
                    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
  7759
                    __eR = nR;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7760
                } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7761
                    __eR = eP[3];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7762
                    eP[0] = eP[-3] = eP[3] = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7763
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7764
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7765
                if (__eG) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7766
                    tG = __eG >> 4;  /* 16th of error */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7767
                    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
  7768
                    eP[1] = tG*5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7769
                    eP[-2] = tG*3;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7770
                    eP[4] = __eG - (tG*15);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7771
                    __eG = nG;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7772
                } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7773
                    __eG = eP[4];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7774
                    eP[1] = eP[-2] = eP[4] = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7775
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7776
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7777
                if (__eB) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7778
                    tB = __eB >> 4;  /* 16th of error */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7779
                    nB = eP[5] + (tB * 7);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7780
                    eP[2] = tB*5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7781
                    eP[-1] = tB*3;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7782
                    eP[5] = __eB - (tB*15);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7783
                    __eB = nB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7784
                } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7785
                    __eB = eP[5];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7786
                    eP[2] = eP[-1] = eP[5] = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7787
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7788
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7789
                eP += 3;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7790
            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7791
        }
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7792
    }
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7793
%}.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7794
    failed ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7795
        self primitiveFailed.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7796
        ^ nil
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7797
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7798
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7799
    ^ pseudoBits
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7800
!
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7801
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7802
floydSteinbergDitheredGrayBitsDepth:depth
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7803
    "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
  7804
     Works for any source depths / photometric,
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7805
     but possibly slow since each pixel is processed individually.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7806
     Redefined by some subclasses for more performance (D8Image/D24Image)"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7807
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7808
    |dstIndex        "{Class: SmallInteger }"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7809
     nextDst         "{Class: SmallInteger }"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7810
     bytesPerOutRow  "{Class: SmallInteger }"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7811
     outBits greyValues greyErrors greyPixels greyLevels
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7812
     errorArray
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7813
     nextErrorArray
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7814
     t
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7815
     w               "{Class: SmallInteger }"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7816
     h               "{Class: SmallInteger }"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7817
     bitCnt          "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7818
     byte            "{Class: SmallInteger }"
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7819
     grey
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7820
     eR eRB eB eLB |
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7821
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7822
    depth > 8 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7823
        self error:'unimplemented conversion'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7824
        ^ nil
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7825
    ].
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7826
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7827
    w := width.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7828
    h := height.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7829
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7830
    bytesPerOutRow := ((w * depth) + 7) // 8.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7831
    outBits := ByteArray uninitializedNew:(bytesPerOutRow * h).
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7832
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7833
    greyLevels := (1 bitShift:depth) - 1.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7834
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7835
    errorArray := Array new:w+2.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7836
    nextErrorArray := Array new:w+2.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7837
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7838
    nextErrorArray atAllPut:0.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7839
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7840
    dstIndex := 1.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7841
    bitCnt := 8.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7842
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7843
    self depth <= 12 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7844
        "/ fetch scaled brightness values outside of loop into a table;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7845
        "/ use table-value in loop
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
        greyValues := self greyMapForRange:(greyLevels).
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
        greyPixels := greyValues collect:[:v | v isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7850
                                                   0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7851
                                               ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7852
                                                   v truncated]].
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
        greyPixels := ByteArray withAll:greyPixels.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7855
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7856
        greyErrors := greyValues collect:[:v | v isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7857
                                                   0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7858
                                               ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7859
                                                   ((v - v truncated) * 1024) truncated
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7860
                                               ]].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7861
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7862
        0 to:(h-1) do:[:y |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7863
            nextDst := dstIndex + bytesPerOutRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7864
            byte := 0.
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
            t := errorArray.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7867
            errorArray := nextErrorArray.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7868
            nextErrorArray := t.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7869
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7870
            nextErrorArray atAllPut:0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7871
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7872
            self valuesAtY:y from:0 to:(w-1) do:[:x :value |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7873
                |e     "{ Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7874
                 pixel "{ Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7875
                 error "{ Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7876
                 e16   "{ Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7877
                 xE    "{ Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7878
                 xN    "{ Class: SmallInteger }" |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7879
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7880
                pixel := greyPixels at:(value + 1).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7881
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7882
                "/ adjust error
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7883
                xE := x + 2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7884
                error := (greyErrors at:(value + 1)) + (errorArray at:xE).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7885
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7886
                byte := byte bitShift:depth.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7887
                error > 512 "0.5" ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7888
                    pixel := pixel + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7889
                    e := error - 1024 "1.0"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7890
                ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7891
                    e := error
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7892
                ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7893
                byte := byte bitOr:pixel.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7894
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7895
                e ~= 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7896
                    e16 := e // 16.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7897
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7898
                    eR  := e16 * 7.              "/ 7/16 to right
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7899
                    eRB := e16 "* 1".            "/ 1/16 to right below
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7900
                    eB  := e16 * 5.              "/ 5/16 to below
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7901
                    eLB := e - eR - eRB - eB.  "/ 3/16 to left below
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7902
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7903
                    xN := xE + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7904
                    eR ~= 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7905
                        errorArray     at:xN put:(errorArray at:xN) + eR.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7906
                    ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7907
                    eRB ~= 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7908
                        nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7909
                    ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7910
                    eB ~= 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7911
                        nextErrorArray at:xE put:(nextErrorArray at:xE) + eB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7912
                    ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7913
                    eLB ~= 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7914
                        xN := xE - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7915
                        nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7916
                    ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7917
                ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7918
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7919
                bitCnt := bitCnt - depth.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7920
                bitCnt == 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7921
                    outBits at:dstIndex put:byte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7922
                    dstIndex := dstIndex + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7923
                    byte := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7924
                    bitCnt := 8.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7925
                ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7926
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7927
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7928
            bitCnt ~~ 8 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7929
                byte := byte bitShift:bitCnt.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7930
                outBits at:dstIndex put:byte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7931
                bitCnt := 8.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7932
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7933
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7934
            dstIndex := nextDst.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7935
        ].
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7936
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7937
        0 to:(h-1) do:[:y |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7938
            nextDst := dstIndex + bytesPerOutRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7939
            byte := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7940
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7941
            t := errorArray.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7942
            errorArray := nextErrorArray.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7943
            nextErrorArray := t.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7944
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7945
            nextErrorArray atAllPut:0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7946
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7947
            self colorsAtY:y from:0 to:(w-1) do:[:x :clr |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7948
                |e     "{ Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7949
                 pixel "{ Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7950
                 error "{ Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7951
                 e16   "{ Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7952
                 xE    "{ Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7953
                 xN    "{ Class: SmallInteger }" |
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
                grey := (clr brightness * greyLevels).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7956
                pixel := grey truncated.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7957
                error := ((grey - pixel) * 1024) truncated.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7958
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7959
                "/ adjust error
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7960
                xE := x + 2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7961
                error := error + (errorArray at:xE).
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
                byte := byte bitShift:depth.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7964
                error > 512 "0.5" ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7965
                    pixel := pixel + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7966
                    e := error - 1024 "1.0"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7967
                ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7968
                    e := error
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7969
                ].
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
                byte := byte bitOr:pixel.
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
                e ~= 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7974
                    e16 := e // 16.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7975
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7976
                    eR  := e16 * 7.              "/ 7/16 to right
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7977
                    eRB := e16 "* 1".            "/ 1/16 to right below
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7978
                    eB  := e16 * 5.              "/ 5/16 to below
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7979
                    eLB := e - eR - eRB - eB.  "/ 3/16 to left below
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
                    xN := xE + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7982
                    eR ~= 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7983
                        errorArray     at:xN put:(errorArray at:xN) + eR.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7984
                    ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7985
                    eRB ~= 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7986
                        nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7987
                    ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7988
                    eB ~= 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7989
                        nextErrorArray at:xE put:(nextErrorArray at:xE) + eB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7990
                    ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7991
                    eLB ~= 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7992
                        xN := xE - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7993
                        nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7994
                    ].
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
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7997
                bitCnt := bitCnt - depth.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7998
                bitCnt == 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  7999
                    outBits at:dstIndex put:byte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8000
                    dstIndex := dstIndex + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8001
                    byte := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8002
                    bitCnt := 8.
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
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8005
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8006
            bitCnt ~~ 8 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8007
                byte := byte bitShift:bitCnt.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8008
                outBits at:dstIndex put:byte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8009
                bitCnt := 8.
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
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8012
            dstIndex := nextDst.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8013
        ].
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8014
    ].
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8015
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8016
    ^ outBits
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8017
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8018
    "Created: 10.6.1996 / 13:28:22 / cg"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8019
    "Modified: 11.6.1996 / 00:13:38 / cg"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8020
!
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8021
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8022
floydSteinbergDitheredMonochromeBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8023
    "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
  8024
     Works for any source depths / photometric,
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8025
     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
  8026
     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
  8027
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8028
    |dstIndex        "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8029
     nextDst         "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8030
     bytesPerMonoRow "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8031
     monoBits greyValues
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8032
     errorArray
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8033
     nextErrorArray
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8034
     e eD t
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8035
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8036
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8037
     bitCnt          "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8038
     byte            "{Class: SmallInteger }"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8039
     grey
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8040
     eR eRB eB eLB |
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8041
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8042
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8043
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8044
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8045
    bytesPerMonoRow := (w + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8046
    monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8047
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8048
    errorArray := Array new:w+2.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8049
    nextErrorArray := Array new:w+2.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8050
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8051
    nextErrorArray atAllPut:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8052
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8053
    dstIndex := 1.
828
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8054
    bitCnt := 8.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8055
    byte := 0.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8056
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8057
    self depth <= 12 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8058
        "/ fetch scaled brightness values outside of loop into a table;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8059
        "/ use table-value in loop
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8060
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8061
        greyValues := self greyMapForRange:(255 * 1024).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8062
        greyValues := greyValues collect:[:v | v rounded].
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
        0 to:(h-1) do:[:y |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8065
            nextDst := dstIndex + bytesPerMonoRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8066
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8067
            t := errorArray.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8068
            errorArray := nextErrorArray.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8069
            nextErrorArray := t.
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
            nextErrorArray atAllPut:0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8072
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8073
            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
  8074
%{
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8075
                int __grey, __e;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8076
                int __byte = __intVal(byte);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8077
                OBJ *__errorArray = __ArrayInstPtr(errorArray)->a_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8078
                OBJ *__nextErrorArray = __ArrayInstPtr(nextErrorArray)->a_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8079
                int __x = __intVal(x);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8080
                int __eR, __eB, __eRB, __eLB, __eI;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8081
                int __bitCnt = __intVal(bitCnt);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8082
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8083
                __grey = __intVal(__ArrayInstPtr(greyValues)->a_element[__intVal(pixel)]);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8084
                __grey += __intVal(__errorArray[__x+1]);
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
                __byte <<= 1;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8087
                if (__grey > 127*1024) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8088
                    __e = __grey - (255*1024);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8089
                    __byte |= 1;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8090
                } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8091
                    __e = __grey;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8092
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8093
                if (__e) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8094
                    __eI = __e >> 4;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8095
                    __eR  = __eI * 7;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8096
                    __eRB = __eI * 1;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8097
                    __eB  = __eI * 5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8098
                    __eLB = __e - __eR - __eRB - __eB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8099
                    __errorArray[__x+2] = __MKSMALLINT(__intVal(__errorArray[__x+2]) + __eR);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8100
                    __nextErrorArray[__x+2] = __MKSMALLINT(__intVal(__nextErrorArray[__x+2]) + __eRB);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8101
                    __nextErrorArray[__x+1] = __MKSMALLINT(__intVal(__nextErrorArray[__x+1]) + __eB);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8102
                    __nextErrorArray[__x  ] = __MKSMALLINT(__intVal(__nextErrorArray[__x  ]) + __eLB);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8103
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
                __bitCnt--;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8106
                if (__bitCnt == 0) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8107
                    int __dstIndex = __intVal(dstIndex);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8108
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8109
                    __ByteArrayInstPtr(monoBits)->ba_element[__dstIndex-1] = __byte;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8110
                    dstIndex = __MKSMALLINT(__dstIndex + 1);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8111
                    __byte = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8112
                    __bitCnt = 8;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8113
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8114
                byte = __MKSMALLINT(__byte);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8115
                bitCnt = __MKSMALLINT(__bitCnt);
828
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8116
%}.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8117
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8118
"/                |eI "{ Class: SmallInteger }"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8119
"/                 xE "{ Class: SmallInteger }"
829
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  8120
"/                 xN "{ Class: SmallInteger }" |
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  8121
"/
828
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8122
"/                "/ get the colors grey value [0 .. 1]
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8123
"/                grey := greyValues at:(pixel + 1).
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8124
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8125
"/                "/ adjust error
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8126
"/                xE := x + 2.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8127
"/                grey := (grey + (errorArray at:xE)).
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8128
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8129
"/                byte := byte bitShift:1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8130
"/                grey > (127*1024) ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8131
"/                    byte := byte bitOr:1.      "/ white
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8132
"/                    e := grey - (255*1024)
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8133
"/                ] ifFalse:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8134
"/                    e := grey                  "/ black
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8135
"/                ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8136
"/                e ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8137
"/                    eD := e.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8138
"/                    eI := e // 16.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8139
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8140
"/                    eR  := eI * 7.              "/ 7/16 to right
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8141
"/                    eRB := eI * 1.              "/ 1/16 to right below
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8142
"/                    eB  := eI * 5.              "/ 5/16 to below
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8143
"/                    eLB := eD - eR - eRB - eB.  "/ 3/16 to left below
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8144
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8145
"/                    xN := xE + 1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8146
"/                    eR ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8147
"/                        errorArray     at:xN put:(errorArray at:xN) + eR.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8148
"/                    ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8149
"/                    eRB ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8150
"/                        nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8151
"/                    ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8152
"/                    eB ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8153
"/                        nextErrorArray at:xE put:(nextErrorArray at:xE) + eB.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8154
"/                    ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8155
"/                    eLB ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8156
"/                        xN := xE - 1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8157
"/                        nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8158
"/                    ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8159
"/                ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8160
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8161
"/                bitCnt := bitCnt - 1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8162
"/                bitCnt == 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8163
"/                    monoBits at:dstIndex put:byte.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8164
"/                    dstIndex := dstIndex + 1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8165
"/                    byte := 0.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8166
"/                    bitCnt := 8.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8167
"/                ].
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8168
                  0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8169
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8170
            bitCnt ~~ 8 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8171
                byte := byte bitShift:bitCnt.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8172
                monoBits at:dstIndex put:byte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8173
                bitCnt := 8.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8174
                byte := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8175
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8176
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8177
            dstIndex := nextDst.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8178
        ].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8179
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8180
        'Image [info]: slow floydSteinberg dither ..' infoPrintCR.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8181
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8182
        0 to:(h-1) do:[:y |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8183
            nextDst := dstIndex + bytesPerMonoRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8184
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8185
            t := errorArray.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8186
            errorArray := nextErrorArray.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8187
            nextErrorArray := t.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8188
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8189
            nextErrorArray atAllPut:0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8190
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8191
            self colorsAtY:y from:0 to:(w-1) do:[:x :clr |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8192
                |eI "{ Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8193
                 xE "{ Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8194
                 xN "{ Class: SmallInteger }" |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8195
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8196
                "/ get the colors grey value [0 .. 1]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8197
                grey := (clr brightness * 255).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8198
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8199
                "/ adjust error
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8200
                xE := x + 2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8201
                grey := (grey + (errorArray at:xE)) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8202
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8203
                byte := byte bitShift:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8204
                grey > 127 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8205
                    byte := byte bitOr:1.      "/ white
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8206
                    e := grey - 255
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8207
                ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8208
                    e := grey                  "/ black
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
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8211
                e ~= 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8212
                    eD := e.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8213
                    eI := e // 16.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8214
                    eR  := eI * 7.              "/ 7/16 to right
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8215
                    eRB := eI "* 1".            "/ 1/16 to right below
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8216
                    eB  := eI * 5.              "/ 5/16 to below
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8217
                    eLB := eD - eR - eRB - eB.  "/ 3/16 to left below
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8218
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8219
                    xN := xE + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8220
                    eR ~= 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8221
                        errorArray     at:xN put:(errorArray at:xN) + eR.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8222
                    ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8223
                    eRB ~= 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8224
                        nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8225
                    ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8226
                    eB ~= 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8227
                        nextErrorArray at:xE put:(nextErrorArray at:xE) + eB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8228
                    ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8229
                    eLB ~= 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8230
                        xN := xE - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8231
                        nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8232
                    ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8233
                ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8234
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8235
                bitCnt := bitCnt - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8236
                bitCnt == 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8237
                    monoBits at:dstIndex put:byte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8238
                    dstIndex := dstIndex + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8239
                    byte := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8240
                    bitCnt := 8.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8241
                ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8242
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8243
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8244
            bitCnt ~~ 8 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8245
                byte := byte bitShift:bitCnt.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8246
                monoBits at:dstIndex put:byte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8247
                bitCnt := 8.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8248
                byte := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8249
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8250
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8251
            dstIndex := nextDst.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8252
        ].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8253
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8254
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8255
    ^ monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8256
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8257
    "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
  8258
    "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
  8259
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8260
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8261
nearestPaintDepth8BitsColors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8262
    "return a nearest paint bitmap from the receiver picture,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8263
     which must be a depth-8 image.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8264
     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
  8265
     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
  8266
     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
  8267
     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
  8268
     Color class."
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8269
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8270
    |pseudoBits
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8271
     fixR    "{Class: SmallInteger }"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8272
     fixG    "{Class: SmallInteger }"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8273
     fixB    "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8274
     fixGfixB
884
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  8275
     r       "{Class: SmallInteger }"
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  8276
     g       "{Class: SmallInteger }"
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  8277
     b       "{Class: SmallInteger }"
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  8278
     idx     "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8279
     idMap lastColor
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8280
     clr|
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8281
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8282
    self depth ~~ 8 ifTrue:[^ nil].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8283
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8284
    photometric == #palette ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8285
        lastColor := colorMap size - 1
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8286
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8287
        lastColor := 255.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8288
    ].
884
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  8289
    idMap := ByteArray uninitializedNew:256.
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  8290
3915
dd2dae91c068 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3914
diff changeset
  8291
    (nRed isNil or:[nGreen isNil or:[nBlue isNil]]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8292
        0 to:lastColor do:[:pix |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8293
            |clr repClr|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8294
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8295
            clr := self colorFromValue:pix.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8296
            repClr := clr nearestIn:fixColors.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8297
            idMap at:(pix+1) put:(fixColors identityIndexOf:repClr)-1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8298
        ].
3914
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  8299
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8300
        fixR := nRed.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8301
        fixR == 0 ifTrue:[ ^ nil].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8302
        fixG := nGreen.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8303
        fixG == 0 ifTrue:[ ^ nil].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8304
        fixB := nBlue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8305
        fixB == 0 ifTrue:[ ^ nil].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8306
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8307
        "/ simple check
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8308
        (fixR * fixG * fixB) ~~ fixColors size ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8309
            self error:'invalid color array passed'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8310
            ^ nil
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
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8313
        "/
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8314
        "/ collect colorIds
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8315
        "/
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8316
        fixGfixB := fixG * fixB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8317
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8318
        0 to:lastColor do:[:pix |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8319
            clr := self colorFromValue:pix.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8320
            r := clr redByte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8321
            g := clr greenByte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8322
            b := clr blueByte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8323
            idx := ((r * (fixR-1) + 128) // 255) * fixGfixB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8324
            idx := idx + (((g * (fixG-1) + 128) // 255) * fixB).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8325
            idx := idx + ((b * (fixB-1) + 128) // 255).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8326
            idMap at:(pix+1) put:(fixColors at:(idx+1)) colorId.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8327
        ].
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8328
    ].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8329
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8330
    pseudoBits := ByteArray uninitializedNew:(width * height).
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8331
884
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  8332
    "/ translate
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  8333
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  8334
    self bits
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8335
        expandPixels:8         "xlate only"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8336
        width:width height:height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8337
        into:pseudoBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8338
        mapping:idMap.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8339
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8340
    ^ pseudoBits
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8341
884
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  8342
    "Modified: 18.6.1996 / 09:18:09 / cg"
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8343
!
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8344
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8345
nfloydSteinbergDitheredDepth8BitsColors:colors
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8346
    "return a floyd-steinberg dithered bitmap from the receiver picture,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8347
     which must be a depth-8 image.
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8348
     This method expects an array of colors to be used for dithering
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8349
     (which need not be a colorCubes colors)."
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8350
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8351
    |pseudoBits
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8352
     rgbBytes
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8353
     ditherRGBBytes ditherColors
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8354
     w       "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8355
     h       "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8356
     index   "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8357
     numR    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8358
     numG    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8359
     numB    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8360
     bitsR    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8361
     bitsG    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8362
     bitsB    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8363
     maxBits  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8364
     maskR    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8365
     maskG    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8366
     maskB    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8367
     shR      "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8368
     shG      "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8369
     shB      "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8370
     ditherIds failed map lastColor colorsByDistance qScramble
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8371
     clrLookup lookupPos cube nCube
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8372
     dR  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8373
     dG  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8374
     dB  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8375
     iR    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8376
     iRG   "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8377
     iRGB  "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8378
     clr
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8379
     rI  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8380
     gI  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8381
     bI  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8382
     maxIDX  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8383
     subCubeColorCollection
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8384
     error
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8385
     dl "{Class: SmallInteger }"|
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8386
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8387
    self depth ~~ 8 ifTrue:[^ nil].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8388
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8389
    "/
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8390
    "/ collect color components as integer values (for integer arithmetic)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8391
    "/
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8392
    rgbBytes := ByteArray uninitializedNew:256 * 3.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8393
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8394
    photometric == #palette ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8395
        lastColor := colorMap size - 1
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8396
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8397
        lastColor := 255.
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8398
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8399
    index := 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8400
    0 to:lastColor do:[:pix |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8401
        clr := self colorFromValue:pix.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8402
        rgbBytes at:index put:(clr redByte).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8403
        rgbBytes at:index+1 put:(clr greenByte).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8404
        rgbBytes at:index+2 put:(clr blueByte).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8405
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8406
        index := index + 3.
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8407
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8408
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8409
    "/ collect valid ditherColors ...
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8410
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8411
    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
  8412
    ditherColors := ditherColors select:[:clr | clr colorId notNil].
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8413
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8414
    "/ collect ditherColor components
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8415
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8416
    lastColor := ditherColors size.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8417
    ditherIds := ByteArray uninitializedNew:lastColor.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8418
    ditherRGBBytes := ByteArray uninitializedNew:(lastColor * 3).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8419
    index := 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8420
    1 to:lastColor do:[:pix |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8421
        clr := ditherColors at:pix.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8422
        ditherRGBBytes at:index put:(clr redByte).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8423
        ditherRGBBytes at:index+1 put:(clr greenByte).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8424
        ditherRGBBytes at:index+2 put:(clr blueByte).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8425
        ditherIds at:pix put:clr colorId.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8426
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8427
        index := index + 3.
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8428
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8429
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8430
    "/ place the ditherColor positions into a color cube
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8431
    bitsR := 5.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8432
    bitsG := 6.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8433
    bitsB := 4.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8434
    maxBits := 6.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8435
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8436
"/    bitsR := 4.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8437
"/    bitsG := 4.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8438
"/    bitsB := 3.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8439
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8440
    numR := 1 bitShift:bitsR.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8441
    numG := 1 bitShift:bitsG.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8442
    numB := 1 bitShift:bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8443
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8444
    maskR := (numR-1) bitShift:(bitsG + bitsB).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8445
    maskG := (numG-1) bitShift:bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8446
    maskB := numB-1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8447
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8448
    shR := -16+bitsR+bitsG+bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8449
    shG := -16+bitsG+bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8450
    shB := -16+bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8451
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8452
    maxIDX := numR*numG*numB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8453
    cube := Array new:maxIDX.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8454
    1 to:lastColor do:[:clrIdx |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8455
        clr := ditherColors at:clrIdx.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8456
        rI := clr scaledRed. rI := (rI bitShift:shR) bitAnd:maskR.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8457
        gI := clr scaledGreen. gI := (gI bitShift:shG) bitAnd:maskG.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8458
        bI := clr scaledBlue. bI := (bI bitShift:shB) bitAnd:maskB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8459
        index := rI + gI + bI + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8460
        subCubeColorCollection := cube at:index.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8461
        subCubeColorCollection isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8462
            subCubeColorCollection := OrderedCollection new.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8463
            cube at:index put:subCubeColorCollection.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8464
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8465
        subCubeColorCollection add:(clrIdx - 1).
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8466
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8467
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8468
    shR := 1 bitShift:(bitsG+bitsB).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8469
    shG := 1 bitShift:(bitsB).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8470
    shB := 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8471
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8472
    1 to:maxIDX do:[:i |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8473
        subCubeColorCollection := cube at:i.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8474
        subCubeColorCollection notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8475
            cube at:i put:(subCubeColorCollection asByteArray)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8476
        ]
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8477
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8478
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8479
"/    nCube := cube copy.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8480
"/
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8481
"/    cube keysAndValuesDo:[:i :indices |
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8482
"/        indices notNil ifTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8483
"/            nCube at:i put:(indices asByteArray)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8484
"/        ] ifFalse:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8485
"/            "/ find nearest color
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8486
"/
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8487
"/            dl := 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8488
"/            [dl < maxBits] whileTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8489
"/                dR := dl negated.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8490
"/                [dR <= dl] whileTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8491
"/                    iR := i + (dR * shR).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8492
"/                    (iR > 0 and:[iR < maxIDX]) ifTrue:[
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8493
"/                        dG := dl negated.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8494
"/                        [dG < dl] whileTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8495
"/                            iRG := iR + (dG * shG).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8496
"/                            (iRG > 0 and:[iRG < maxIDX]) ifTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8497
"/                                dB := dl negated.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8498
"/                                [dB < dl] whileTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8499
"/                                    iRGB := iRG + dB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8500
"/                                    (iRG > 0 and:[iRG < maxIDX]) ifTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8501
"/                                        (cube at:iRGB) notNil ifTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8502
"/                                            nCube at:i put:(cube at:iRGB).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8503
"/                                            dB := dG := dR := dl := 999.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8504
"/                                        ]
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8505
"/                                    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8506
"/                                    dB := dB + 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8507
"/                                ]
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
"/                            dG := dG + 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8510
"/                        ]
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
"/                    dR := dR + 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8513
"/                ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8514
"/                dl := dl + 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8515
"/            ]
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
"/    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8518
"/self halt.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8519
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8520
    "/ now, cube contains collections of colors which are
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8521
    "/ positioned in a subCube; quickly accessed by a lookup
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8522
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8523
    pseudoBits := ByteArray uninitializedNew:(width * height).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8524
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8525
    w := width.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8526
    h := height.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8527
    error := ByteArray new:(w+2)*3*2.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8528
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
#define BITSR   5
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8531
#define BITSG   6
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8532
#define BITSB   4
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8533
#define MAXBITS 6
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8534
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8535
#define xBITSR   4
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8536
#define xBITSG   4
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8537
#define xBITSB   3
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8538
#define xMAXBITS 4
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8539
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8540
#define NR      32 /* (1<<BITSR) */
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8541
#define NG      64 /* (1<<BITSG) */
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8542
#define NB      16 /* (1<<BITSB) */
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8543
#define MAXRGB  64 /* (1<<MAXBITS) */
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
#define SHR     (BITSG+BITSB)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8546
#define SHG     BITSB
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8547
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8548
#define REMEMBER_SEARCH
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8549
#define xNO_FLOYD_STEINBERG
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8550
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8551
    int __x, __y;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8552
    int __eR, __eG, __eB;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8553
    unsigned char *srcP, *dstP;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8554
    unsigned char *rgbP;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8555
    unsigned char *idP;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8556
    short *errP, *eP;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8557
    int __fR, __fG, __fB;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8558
    int idx;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8559
    int __w = __intVal(w);
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8560
    int __h = __intVal(h);
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8561
    int __nColors = __intVal(lastColor);
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8562
    int __wR = -1, __wG, __wB;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8563
    OBJ *__cube;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8564
    int cubeIndex, cubeIndex2;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8565
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8566
    if (__isByteArrayLike(__INST(bytes))
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8567
     && __isByteArray(pseudoBits)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8568
     && __isByteArray(rgbBytes)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8569
     && __isByteArray(ditherRGBBytes)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8570
     && __isByteArray(ditherIds)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8571
     && __isByteArray(error)) {
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8572
        failed = false;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8573
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8574
        srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8575
        dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8576
        rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8577
        idP = __ByteArrayInstPtr(ditherIds)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8578
        errP = (short *) __ByteArrayInstPtr(error)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8579
        __cube = __ArrayInstPtr(cube)->a_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8580
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8581
        eP = errP;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8582
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8583
        for (__y=__h; __y>0; __y--) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8584
            eP = &(errP[3]);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8585
            __eR = eP[0];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8586
            __eG = eP[1];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8587
            __eB = eP[2];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8588
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8589
            for (__x=__w; __x>0; __x--) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8590
                int __want;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8591
                int pix;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8592
                int __wantR, __wantG, __wantB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8593
                int idx;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8594
                int tR, tG, tB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8595
                int nR, nG, nB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8596
                int __dR, __dG, __dB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8597
                int minDelta, bestIdx;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8598
                int __iR, __iG, __iB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8599
                int cR, cG, cB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8600
                int delta;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8601
                OBJ subCubeColors;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8602
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8603
                pix = *srcP++;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8604
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8605
                /*
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8606
                 * wR, wG and wB is the wanted r/g/b value;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8607
                 */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8608
                idx = pix+pix+pix;  /* pix * 3 */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8609
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8610
                __wR = __wantR = rgbP[idx] + __eR;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8611
                __wG = __wantG = rgbP[idx+1] + __eG;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8612
                __wB = __wantB = rgbP[idx+2] + __eB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8613
                if(__wR > 255) __wR = 255;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8614
                else if (__wR < 0) __wR = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8615
                if(__wG > 255) __wG = 255;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8616
                else if (__wG < 0) __wG = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8617
                if(__wB > 255) __wB = 255;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8618
                else if (__wB < 0) __wB = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8619
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8620
                __iR = __wR >> (8-BITSR);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8621
                __iG = __wG >> (8-BITSG);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8622
                __iB = __wB >> (8-BITSB);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8623
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8624
                cubeIndex = (__iR<<SHR) + (__iG<<SHG) + __iB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8625
                subCubeColors = __cube[cubeIndex];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8626
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8627
                if (subCubeColors == nil) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8628
                    /* search around in spirals, for the first match */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8629
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8630
                    delta = 1;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8631
                    while (delta < MAXRGB) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8632
                        /* check plane above */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8633
                        cR = __iR + delta;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8634
                        if ((unsigned)cR < NR) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8635
                            for (cG=__iG-delta; cG<=__iG+delta; cG++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8636
                                if ((unsigned)cG < NG) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8637
                                    for (cB=__iB-delta; cB<=__iB+delta; cB++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8638
                                        if ((unsigned)cB < NB) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8639
                                            cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8640
                                            subCubeColors = __cube[cubeIndex2];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8641
                                            if (__isNonNilObject(subCubeColors)) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8642
                                                goto found;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8643
                                            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8644
                                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8645
                                    }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8646
                                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8647
                            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8648
                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8649
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8650
                        /* check plane below */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8651
                        cR = __iR - delta;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8652
                        if ((unsigned)cR < NR) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8653
                            for (cG=__iG-delta; cG<=__iG+delta; cG++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8654
                                if ((unsigned)cG < NG) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8655
                                    for (cB=__iB-delta; cB<=__iB+delta; cB++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8656
                                        if ((unsigned)cB < NB) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8657
                                            cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8658
                                            subCubeColors = __cube[cubeIndex2];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8659
                                            if (__isNonNilObject(subCubeColors)) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8660
                                                goto found;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8661
                                            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8662
                                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8663
                                    }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8664
                                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8665
                            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8666
                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8667
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8668
                        /* check plane to the right */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8669
                        cG = __iG + delta;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8670
                        if ((unsigned)cG < NG) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8671
                            for (cR=__iR-delta+1; cR<=__iR+delta-1; cR++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8672
                                if ((unsigned)cR < NR) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8673
                                    for (cB=__iB-delta; cB<=__iB+delta; cB++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8674
                                        if ((unsigned)cB < NB) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8675
                                            cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8676
                                            subCubeColors = __cube[cubeIndex2];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8677
                                            if (__isNonNilObject(subCubeColors)) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8678
                                                goto found;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8679
                                            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8680
                                        }
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
                                }
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
                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8685
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8686
                        /* check plane to the left */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8687
                        cG = __iG - delta;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8688
                        if ((unsigned)cG < NG) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8689
                            for (cR=__iR-delta+1; cR<=__iR+delta-1; cR++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8690
                                if ((unsigned)cR < NR) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8691
                                    for (cB=__iB-delta; cB<=__iB+delta; cB++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8692
                                        if ((unsigned)cB < NB) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8693
                                            cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8694
                                            subCubeColors = __cube[cubeIndex2];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8695
                                            if (__isNonNilObject(subCubeColors)) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8696
                                                goto found;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8697
                                            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8698
                                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8699
                                    }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8700
                                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8701
                            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8702
                        }
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
                        /* check plane at back */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8705
                        cB = __iB + delta;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8706
                        if ((unsigned)cB < NB) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8707
                            for (cR=__iR-delta+1; cR<=(__iR+delta-1); cR++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8708
                                if ((unsigned)cR < NR) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8709
                                    for (cG=__iG-delta+1; cG<=(__iG+delta-1); cG++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8710
                                        if ((unsigned)cG < NG) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8711
                                            cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8712
                                            subCubeColors = __cube[cubeIndex2];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8713
                                            if (__isNonNilObject(subCubeColors)) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8714
                                                goto found;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8715
                                            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8716
                                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8717
                                    }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8718
                                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8719
                            }
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
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8722
                        /* check plane at front */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8723
                        cB = __iB - delta;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8724
                        if ((unsigned)cB < NB) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8725
                            for (cR=__iR-delta+1; cR<=(__iR+delta-1); cR++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8726
                                if ((unsigned)cR < NR) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8727
                                    for (cG=__iG-delta+1; cG<=(__iG+delta-1); cG++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8728
                                        if ((unsigned)cG < NG) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8729
                                            cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8730
                                            subCubeColors = __cube[cubeIndex2];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8731
                                            if (__isNonNilObject(subCubeColors)) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8732
                                                goto found;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8733
                                            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8734
                                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8735
                                    }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8736
                                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8737
                            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8738
                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8739
                        delta = delta + 1;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8740
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8741
                    }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8742
                    /* cannot happen - will lead to a segmentation violation ... */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8743
                    subCubeColors = nil;
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8744
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8745
    found:
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8746
                    __iR = cR;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8747
                    __iG = cG;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8748
                    __iB = cB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8749
                    bestIdx = __ByteArrayInstPtr(subCubeColors)->ba_element[0];
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8750
#ifdef REMEMBER_SEARCH
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8751
                    __cube[cubeIndex] = __MKSMALLINT(bestIdx);
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8752
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8753
                } else {
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8754
#ifdef REMEMBER_SEARCH
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8755
                    if (__isSmallInteger(subCubeColors)) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8756
                        bestIdx = __intVal(subCubeColors);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8757
                    } else
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8758
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8759
                    {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8760
                        bestIdx = __ByteArrayInstPtr(subCubeColors)->ba_element[0];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8761
                    }
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
                 * ok, now, we have found a collection of nearby
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8766
                 * colors in subCubeColors.
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
                 * 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
  8769
                 * don't care for searching the best - simply take the
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8770
                 * first color found there.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8771
                 * (statistic reduces the error to even a smaller value).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8772
                 * There is no real problem due to that error, since
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8773
                 * it will be diffused anyway ...
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8774
                 */
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8775
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8776
#ifndef NO_FLOYD_STEINBERG
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8777
                {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8778
                    unsigned char *dp;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8779
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
                     * fetch that colors r/g/b components
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
                    dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8784
                    dp += bestIdx * 3;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8785
                    __dR = dp[0];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8786
                    __dG = dp[1];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8787
                    __dB = dp[2];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8788
                }
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8789
#endif
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8790
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8791
/*
4725
c8896df7bd3f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4717
diff changeset
  8792
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
  8793
                __wantR, __wantG, __wantB,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8794
                __wR, __wG, __wB,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8795
                __dR, __dG, __dB);
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8796
*/
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8797
                /*
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8798
                 * store the corresponding dither colors colorId
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
                *dstP++ = idP[bestIdx];
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8801
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8802
#ifndef NO_FLOYD_STEINBERG
7522
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
                 * the new error & distribute the error
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8805
                 */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8806
                __eR = __wantR - __dR;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8807
                if (__eR) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8808
                    tR = __eR >> 4;  /* 16th of error */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8809
                    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
  8810
                    eP[0] = tR*5;         /* 5/16th for (x / y+1) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8811
                    eP[-3] = tR*3;        /* 3/16th for (x-1 / y+1) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8812
                    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
  8813
                    __eR = nR;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8814
                } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8815
                    __eR = eP[3];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8816
                    eP[0] = eP[-3] = eP[3] = 0;
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
                __eG = __wantG - __dG;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8820
                if (__eG) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8821
                    tG = __eG >> 4;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8822
                    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
  8823
                    eP[1] = tG*5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8824
                    eP[-2] = tG*3;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8825
                    eP[4] = __eG - (tG*15);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8826
                    __eG = nG;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8827
                } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8828
                    __eG = eP[4];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8829
                    eP[1] = eP[-2] = eP[4] = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8830
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8831
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8832
                __eB = __wantB - __dB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8833
                if (__eB) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8834
                    tB = __eB >> 4;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8835
                    nB = eP[5] + (tB * 7);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8836
                    eP[2] = tB*5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8837
                    eP[-1] = tB*3;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8838
                    eP[5] = __eB - (tB*15);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8839
                    __eB = nB;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8840
                } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8841
                    __eB = eP[5];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8842
                    eP[2] = eP[-1] = eP[5] = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8843
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8844
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8845
                eP += 3;
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8846
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8847
            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8848
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8849
            /*
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8850
             * allow for an interrupt after every row.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8851
             * but care to refetch C variables
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8852
             */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8853
            if (InterruptPending) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8854
                int d_srcP = srcP - __ByteArrayInstPtr(__INST(bytes))->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8855
                int d_dstP = dstP - __ByteArrayInstPtr(pseudoBits)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8856
                int d_errP = errP - (short *) __ByteArrayInstPtr(error)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8857
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8858
                __interrupt__();
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8859
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8860
                srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element + d_srcP;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8861
                dstP = __ByteArrayInstPtr(pseudoBits)->ba_element + d_dstP;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8862
                rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8863
                idP = __ByteArrayInstPtr(ditherIds)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8864
                errP = (short *) __ByteArrayInstPtr(error)->ba_element + d_errP;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8865
                __cube = __ArrayInstPtr(cube)->a_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8866
            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8867
        }
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8868
    }
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8869
%}.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8870
    failed ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8871
        self primitiveFailed.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8872
        ^ nil
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8873
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8874
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8875
    ^ pseudoBits
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
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8878
orderedDitheredGrayBitsDepth:depth
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8879
    "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
  8880
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8881
    ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8882
        orderedDitheredGrayBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8883
        ditherWidth:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8884
        depth:depth.
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8885
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8886
    "Created: 24.6.1997 / 22:20:12 / cg"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8887
!
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8888
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8889
orderedDitheredGrayBitsWithDitherMatrix:ditherMatrix ditherWidth:dW depth:depth
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8890
    "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
  8891
     with a constant ditherMatrix, this can be used for thresholding.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8892
     Works for any source depths / photometric,
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8893
     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
  8894
     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
  8895
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8896
    |dH nDither
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8897
     greyLevels greyValues greyPixels greyErrors
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8898
     dstIndex        "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8899
     nextDst
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8900
     bytesPerOutRow  "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8901
     pixelsPerByte   "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8902
     outBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8903
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8904
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8905
     bitCnt          "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8906
     byte            "{Class: SmallInteger }" |
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8907
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8908
    depth > 8 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8909
        'IMAGE: unimplemented orderedDither conversion' errorPrintCR.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8910
        ^ nil
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8911
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8912
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8913
    nDither := ditherMatrix size.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8914
    dH := nDither / dW.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8915
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8916
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8917
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8918
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8919
    greyLevels := 1 bitShift:depth.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8920
    pixelsPerByte := 8 / depth.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8921
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8922
    bytesPerOutRow := (w * depth + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8923
    outBits := ByteArray uninitializedNew:(bytesPerOutRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8924
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8925
    dstIndex := 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8926
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8927
    self bitsPerPixel <= 12 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8928
        "/ fetch scaled brightness values outside of loop into a table;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8929
        "/ use table-value in loop
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8930
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8931
        greyValues := self greyMapForRange:(greyLevels-1).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8932
        greyPixels := greyValues collect:[:v | v isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8933
                                                   0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8934
                                               ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8935
                                                   v truncated]].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8936
        greyPixels := ByteArray withAll:greyPixels.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8937
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8938
        greyErrors := greyValues collect:[:v | v isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8939
                                                   0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8940
                                               ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8941
                                                   ((v - v truncated) * nDither) rounded
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8942
                                               ]].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8943
        greyErrors := ByteArray withAll:greyErrors.
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
        0 to:(h-1) do:[:y |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8946
            nextDst := dstIndex + bytesPerOutRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8947
            byte := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8948
            bitCnt := 8.
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
            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
  8951
%{
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8952
                int __dW = __intVal(dW);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8953
                int __byte = __intVal(byte);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8954
                /* Note: __value is reserved in Visual C++ 8 (2005) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8955
                int __val = __intVal(value);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8956
                int __dT;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8957
                int __dstIdx;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8958
                int __pixel, __grey;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8959
                int __bitCnt = __intVal(bitCnt);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8960
                unsigned char *__greyPixels = __ByteArrayInstPtr(greyPixels)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8961
                unsigned char *__greyErrors = __ByteArrayInstPtr(greyErrors)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8962
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8963
                __pixel = __greyPixels[__val];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8964
                __grey = __greyErrors[__val];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8965
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8966
                __dT = __ByteArrayInstPtr(ditherMatrix)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8967
                            ->ba_element[__intVal(x) % __dW
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8968
                                         + (__intVal(y) % __intVal(dH)) * __dW];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8969
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8970
                if (__grey > __dT) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8971
                    __pixel++;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8972
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8973
                __byte = (__byte << __intVal(depth)) | __pixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8974
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8975
                __bitCnt = __bitCnt - __intVal(depth);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8976
                if (__bitCnt == 0) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8977
                    __dstIdx = __intVal(dstIndex);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8978
                    __ByteArrayInstPtr(outBits)->ba_element[__dstIdx-1] = __byte;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8979
                    __dstIdx = __dstIdx + 1;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8980
                    dstIndex = __MKSMALLINT(__dstIdx);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8981
                    __byte = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8982
                    __bitCnt = 8;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8983
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8984
                byte = __MKSMALLINT(__byte);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8985
                bitCnt = __MKSMALLINT(__bitCnt);
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8986
%}.
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8987
                0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8988
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8989
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8990
            bitCnt ~~ 8 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8991
                byte := byte bitShift:bitCnt.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8992
                outBits at:dstIndex put:byte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8993
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8994
            dstIndex := nextDst.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8995
        ].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8996
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8997
        'Image [info]: slow ordered dither ..' infoPrintCR.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8998
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  8999
        0 to:(h-1) do:[:y |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9000
            nextDst := dstIndex + bytesPerOutRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9001
            byte := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9002
            bitCnt := 8.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9003
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9004
            "/ this is the representaion independent (but slow)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9005
            "/ inner loop - it extracts colors from the receiver
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9006
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9007
            self colorsAtY:y from:0 to:(w-1) do:[:x :clr |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9008
                |dstClr grey dT pixel|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9009
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9010
                "/ get the colors grey value [0 .. 1]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9011
                grey := clr brightness.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9012
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9013
                "/ remap into [0 .. greyLevels-1]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9014
                grey := grey * (greyLevels-1).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9015
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9016
                "/ get threshold pixel [0 .. greyLevels-1]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9017
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9018
                pixel := grey truncated.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9019
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9020
                "/ compute the error [0..1]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9021
                grey := grey - pixel.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9022
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9023
                "/ map into dither space [0 .. nDither]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9024
                grey := (grey * (nDither)) rounded.
809
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
%{
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9027
                int __dW = __intVal(dW);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9028
                int __byte = __intVal(byte);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9029
                int __dT;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9030
                int __dstIdx;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9031
                int __pixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9032
                int __bitCnt = __intVal(bitCnt);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9033
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9034
                __dT = __ByteArrayInstPtr(ditherMatrix)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9035
                            ->ba_element[__intVal(x) % __dW
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9036
                                         + (__intVal(y) % __intVal(dH)) * __dW];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9037
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9038
                __pixel = __intVal(pixel);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9039
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9040
                if (__intVal(grey) > __dT) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9041
                    __pixel++;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9042
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9043
                __byte = (__byte << __intVal(depth)) | __pixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9044
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9045
                __bitCnt = __bitCnt - __intVal(depth);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9046
                if (__bitCnt == 0) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9047
                    __dstIdx = __intVal(dstIndex);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9048
                    __ByteArrayInstPtr(outBits)->ba_element[__dstIdx-1] = __byte;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9049
                    __dstIdx = __dstIdx + 1;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9050
                    dstIndex = __MKSMALLINT(__dstIdx);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9051
                    __byte = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9052
                    __bitCnt = 8;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9053
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9054
                byte = __MKSMALLINT(__byte);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9055
                bitCnt = __MKSMALLINT(__bitCnt);
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9056
%}.
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9057
                0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9058
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9059
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9060
            bitCnt ~~ 8 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9061
                byte := byte bitShift:bitCnt.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9062
                outBits at:dstIndex put:byte.
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
            dstIndex := nextDst.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9065
        ].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9066
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9067
    ^ outBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9068
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9069
831
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  9070
orderedDitheredMonochromeBits
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  9071
    "return the bitmap for a dithered monochrome bitmap from the image;
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  9072
     using a default ditherMatrix."
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  9073
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  9074
    ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9075
        orderedDitheredMonochromeBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9076
        ditherWidth:8
831
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  9077
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  9078
    "Created: 11.6.1996 / 16:48:57 / cg"
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  9079
!
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  9080
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9081
orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9082
    "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
  9083
     with a constant ditherMatrix, this can be used for thresholding.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9084
     Works for any source depths / photometric,
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9085
     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
  9086
     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
  9087
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9088
    |dH nDither
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9089
     greyValues
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9090
     dstIndex        "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9091
     nextDst         "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9092
     bytesPerMonoRow "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9093
     monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9094
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9095
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9096
     bitCnt          "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9097
     byte            "{Class: SmallInteger }" |
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9098
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9099
    nDither := ditherMatrix size.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9100
    dH := nDither / dW.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9101
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9102
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9103
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9104
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9105
    bytesPerMonoRow := (w + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9106
    monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9107
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9108
    dstIndex := 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9109
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9110
    self bitsPerPixel <= 12 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9111
        "/ fetch scaled brightness values outside of loop into a table;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9112
        "/ use table-value in loop
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
        greyValues := self greyByteMapForRange:nDither.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9115
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9116
        0 to:(h-1) do:[:y |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9117
            nextDst := dstIndex + bytesPerMonoRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9118
            byte := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9119
            bitCnt := 8.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9120
            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
  9121
%{
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9122
                int __dW = __intVal(dW);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9123
                int __byte = __intVal(byte);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9124
                int __dT;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9125
                int __dstIdx;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9126
                int __bitCnt = __intVal(bitCnt);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9127
                int __grey;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9128
                unsigned char *__greyValues = __ByteArrayInstPtr(greyValues)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9129
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9130
                __grey = __greyValues[__intVal(value)];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9131
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9132
                __dT = __ByteArrayInstPtr(ditherMatrix)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9133
                            ->ba_element[__intVal(x) % __dW
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9134
                                         + (__intVal(y) % __intVal(dH)) * __dW];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9135
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9136
                __byte = __byte << 1;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9137
                if (__grey > __dT) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9138
                    __byte = __byte | 1;            /* white */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9139
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9140
                __bitCnt = __bitCnt - 1;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9141
                if (__bitCnt == 0) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9142
                    __dstIdx = __intVal(dstIndex);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9143
                    __ByteArrayInstPtr(monoBits)->ba_element[__dstIdx-1] = __byte;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9144
                    __dstIdx = __dstIdx + 1;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9145
                    dstIndex = __MKSMALLINT(__dstIdx);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9146
                    __byte = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9147
                    __bitCnt = 8;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9148
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9149
                byte = __MKSMALLINT(__byte);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9150
                bitCnt = __MKSMALLINT(__bitCnt);
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9151
%}.
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9152
                0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9153
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9154
            bitCnt ~~ 8 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9155
                byte := byte bitShift:bitCnt.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9156
                monoBits at:dstIndex put:byte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9157
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9158
            dstIndex := nextDst.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9159
        ].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9160
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9161
        'Image [info]: slow ordered dither ..' infoPrintCR.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9162
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9163
        0 to:(h-1) do:[:y |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9164
            nextDst := dstIndex + bytesPerMonoRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9165
            byte := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9166
            bitCnt := 8.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9167
            self colorsAtY:y from:0 to:(w-1) do:[:x :clr |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9168
                |dstClr grey dT|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9169
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9170
                "/ get the colors grey value [0 .. 1]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9171
                grey := clr brightness.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9172
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9173
                "/ map into dither space [0 .. nDither]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9174
                grey := (grey * (nDither)) rounded.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9175
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9176
%{
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9177
                int __dW = __intVal(dW);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9178
                int __byte = __intVal(byte);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9179
                int __dT;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9180
                int __dstIdx;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9181
                int __bitCnt = __intVal(bitCnt);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9182
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9183
                __dT = __ByteArrayInstPtr(ditherMatrix)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9184
                            ->ba_element[__intVal(x) % __dW
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9185
                                         + (__intVal(y) % __intVal(dH)) * __dW];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9186
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9187
                __byte = __byte << 1;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9188
                if (__intVal(grey) > __dT) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9189
                    __byte = __byte | 1;            /* white */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9190
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9191
                __bitCnt = __bitCnt - 1;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9192
                if (__bitCnt == 0) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9193
                    __dstIdx = __intVal(dstIndex);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9194
                    __ByteArrayInstPtr(monoBits)->ba_element[__dstIdx-1] = __byte;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9195
                    __dstIdx = __dstIdx + 1;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9196
                    dstIndex = __MKSMALLINT(__dstIdx);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9197
                    __byte = 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9198
                    __bitCnt = 8;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9199
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9200
                byte = __MKSMALLINT(__byte);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9201
                bitCnt = __MKSMALLINT(__bitCnt);
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9202
%}.
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9203
                0
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9204
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9205
"/                dT := ditherMatrix at:(x \\ dW) + (y \\ dH * dW) + 1.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9206
"/
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9207
"/                byte := byte bitShift:1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9208
"/                grey < dT ifTrue:[
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9209
"/                    byte := byte bitOr: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
"/                bitCnt := bitCnt - 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9212
"/                bitCnt == 0 ifTrue:[
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9213
"/                    monoBits at:dstIndex put:byte.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9214
"/                    dstIndex := dstIndex + 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9215
"/                    byte := 0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9216
"/                    bitCnt := 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9217
"/                ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9218
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9219
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9220
            bitCnt ~~ 8 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9221
                byte := byte bitShift:bitCnt.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9222
                monoBits at:dstIndex put:byte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9223
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9224
            dstIndex := nextDst.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9225
        ].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9226
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9227
    ^ monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9228
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9229
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9230
stevensonArceDitheredMonochromeBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9231
    "return the bitmap for a dithered monochrome bitmap from the image.
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9232
     Works for any source depths / photometric.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9233
     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
  9234
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  9235
    |dstIndex        "{Class: SmallInteger }"
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9236
     nextDst         "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9237
     bytesPerMonoRow "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9238
     monoBits greyValues
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9239
     errorArray
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9240
     errorArray1 errorArray2 errorArray3
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9241
     e t
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9242
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9243
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9244
     bitCnt          "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9245
     byte            "{Class: SmallInteger }"
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  9246
     grey
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  9247
     xE              "{Class: SmallInteger }" |
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9248
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9249
    self depth > 12 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9250
        ^ self floydSteinbergDitheredMonochromeBits
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9251
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9252
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9253
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9254
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9255
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9256
    bytesPerMonoRow := (w + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9257
    monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9258
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9259
    errorArray := Array new:(w+6).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9260
    errorArray1 := Array new:(w+6) withAll:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9261
    errorArray2 := Array new:(w+6) withAll:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9262
    errorArray3 := Array new:(w+6) withAll:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9263
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9264
    dstIndex := 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9265
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9266
    "/ 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
  9267
    "/ use table-value in loop
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9268
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9269
    greyValues := self greyMapForRange:(255 * 1024).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9270
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9271
    0 to:(h-1) do:[:y |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9272
        nextDst := dstIndex + bytesPerMonoRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9273
        byte := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9274
        bitCnt := 8.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9275
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9276
        t := errorArray.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9277
        errorArray := errorArray1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9278
        errorArray1 := errorArray2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9279
        errorArray2 := errorArray3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9280
        errorArray3 := t.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9281
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9282
        errorArray3 atAllPut:0.
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
        self valuesAtY:y from:0 to:(w-1) do:[:x :pixel |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9285
            |eP eD|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9286
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9287
            "/ get the colors grey value [0 .. 1]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9288
            grey := greyValues at:(pixel + 1).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9289
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9290
            "/ adjust error
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9291
            xE := x + 3 + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9292
            grey := (grey + (errorArray at:xE)).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9293
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9294
            byte := byte bitShift:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9295
            grey > (127 * 1024) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9296
                byte := byte bitOr:1.      "/ white
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9297
                e := grey - (255 * 1024)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9298
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9299
                e := grey                  "/ black
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
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9302
            e ~= 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9303
                "/ distribute the error:
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9304
                "/                  XX    32
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9305
                "/         12    26    30    16
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9306
                "/            12    26    12
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9307
                "/          5    12    12     5
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9308
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9309
                eD := e.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9310
                e := e // 200.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9311
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9312
                eP := e * 32. eD := eD - eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9313
                errorArray at:xE+2 put:(errorArray at:xE+2) + eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9314
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9315
                eP := e * 30. eD := eD - eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9316
                errorArray1 at:xE+1 put:(errorArray1 at:xE+1) + eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9317
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9318
                eP := e * 16. eD := eD - eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9319
                errorArray1 at:xE+3 put:(errorArray1 at:xE+3) + eP.
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
                eP := e * 26. eD := eD - eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9322
                errorArray1 at:xE-1 put:(errorArray1 at:xE-1) + eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9323
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9324
                eD := eD - eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9325
                errorArray2 at:xE put:(errorArray2 at:xE) + eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9326
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9327
                eP := e * 12. eD := eD - eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9328
                errorArray1 at:xE-3 put:(errorArray1 at:xE-3) + eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9329
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9330
                eD := eD - eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9331
                errorArray2 at:xE-2 put:(errorArray2 at:xE-2) + eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9332
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9333
                eD := eD - eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9334
                errorArray2 at:xE+2 put:(errorArray2 at:xE+2) + eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9335
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9336
                eD := eD - eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9337
                errorArray3 at:xE-1 put:(errorArray3 at:xE-1) + eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9338
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9339
                eD := eD - eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9340
                errorArray3 at:xE+1 put:(errorArray3 at:xE+1) + eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9341
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9342
                eP := e * 5. eD := eD - eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9343
                errorArray3 at:xE-3 put:(errorArray3 at:xE-3) + eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9344
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9345
                eP := eD.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9346
                errorArray3 at:xE+3 put:(errorArray3 at:xE+3) + eP.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9347
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9348
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9349
            bitCnt := bitCnt - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9350
            bitCnt == 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9351
                monoBits at:dstIndex put:byte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9352
                dstIndex := dstIndex + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9353
                byte := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9354
                bitCnt := 8.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9355
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9356
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9357
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9358
        bitCnt ~~ 8 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9359
            byte := byte bitShift:bitCnt.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9360
            monoBits at:dstIndex put:byte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9361
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9362
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9363
        dstIndex := nextDst.
809
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
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9366
    ^ monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9367
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9368
    "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
  9369
    "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
  9370
! !
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9371
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9372
!Image methodsFor:'drawing'!
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9373
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9374
displayArcOrigin:origin corner:corner from:startAngle angle:angle withColor:aColor
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9375
    "draw a circle with some pixel value.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9376
     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
  9377
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9378
    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
  9379
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9380
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9381
     |cm i|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9382
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9383
     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
  9384
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9385
     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
  9386
     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
  9387
     i inspect.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9388
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9389
!
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9390
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9391
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
  9392
    "draw a circle with some pixel value.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9393
     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
  9394
     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
  9395
     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
  9396
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9397
    |tempForm wI "{ Class: SmallInteger }"
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9398
     hI "{ Class: SmallInteger }" tempImage|
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9399
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9400
    wI := self width.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9401
    hI := self height.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9402
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9403
    tempForm := Form width:wI height:hI depth:1 onDevice:Screen current.
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  9404
    tempForm
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9405
        paint:(Color colorId:1) on:(Color colorId:0);
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9406
        clear.
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9407
    tempForm displayArcOrigin:origin corner:corner from:startAngle angle:angle.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9408
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9409
    tempImage := tempForm asImage.
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9410
    0 to:hI-1 do:[:yRun|
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9411
        0 to:wI-1 do:[:xRun|
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9412
            (tempImage pixelAtX:xRun y:yRun) == 1 ifTrue:[
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9413
                self atImageAndMask:xRun@yRun putValue:aPixelValueOrNil.
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9414
            ].
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9415
        ].
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9416
    ].
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9417
    tempForm destroy.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9418
    tempImage close.
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9419
    self release. "/ device-image is no longer valid
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9420
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9421
    "
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9422
     |cm i|
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9423
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9424
     cm :=  Array with:Color white with:Color black with:Color red.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9425
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9426
     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
  9427
     i displayArcOrigin:100@100 corner:200@200 from:0 angle:90 withColor:Color red.
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9428
     i inspect.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9429
    "
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9430
!
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9431
4994
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9432
drawEllipse:aRectangle withColor:aColor
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9433
    "draw a circle with some pixel value.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9434
     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
  9435
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9436
    self drawEllipse:aRectangle withValue:(self valueFromColor:aColor)
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9437
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9438
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9439
     |cm i|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9440
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9441
     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
  9442
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9443
     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
  9444
     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
  9445
     i inspect.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9446
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9447
!
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9448
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9449
drawEllipse:aRectangle withValue:aPixelValueOrNil
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9450
    "draw a circle with some pixel value.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9451
     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
  9452
     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
  9453
     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
  9454
4994
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9455
    |tempForm xI "{ Class: SmallInteger }"
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9456
     yI "{ Class: SmallInteger }"
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9457
     wI "{ Class: SmallInteger }"
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9458
     hI "{ Class: SmallInteger }" tempImage|
4994
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9459
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9460
    wI := aRectangle width.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9461
    hI := aRectangle height.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9462
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9463
    tempForm := Form width:wI height:hI depth:1 onDevice:Screen current.
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  9464
    tempForm
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9465
        paint:(Color colorId:1) on:(Color colorId:0);
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9466
        clear.
4994
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9467
    tempForm displayArcIn:(0@0 extent:wI@hI) from:0 angle:360.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9468
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9469
    xI := aRectangle left.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9470
    yI := aRectangle top.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9471
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9472
    tempImage := tempForm asImage.
4994
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9473
    0 to:hI-1 do:[:yRun|
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9474
        0 to:wI-1 do:[:xRun|
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9475
            (tempImage pixelAtX:xRun y:yRun) == 1 ifTrue:[
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9476
                self atImageAndMask: (xI+xRun)@(yI+yRun) putValue:aPixelValueOrNil.
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9477
            ].
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9478
        ].
4994
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9479
    ].
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9480
    tempForm destroy.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9481
    tempImage close.
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9482
    self release. "/ device-image is no longer valid
4994
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9483
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9484
    "
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9485
     |cm i|
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9486
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9487
     cm :=  Array with:Color white with:Color black with:Color red.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9488
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9489
     i := Depth8Image extent:300@400 depth:8 palette:cm.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9490
     i drawEllipse:(0@0 corner:80@100) withColor:Color red.
4994
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9491
     i inspect.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9492
    "
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9493
!
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9494
5235
e9ab91666ebf *** empty log message ***
sr
parents: 5216
diff changeset
  9495
drawLineFrom:startPoint to:endPoint withColor:aColorOrPixelValue
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9496
    "draw a line with some pixel value.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9497
     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
  9498
     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
  9499
     (such as the HumanReadableImageGenerator)"
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9500
5235
e9ab91666ebf *** empty log message ***
sr
parents: 5216
diff changeset
  9501
    |pixelValue|
e9ab91666ebf *** empty log message ***
sr
parents: 5216
diff changeset
  9502
e9ab91666ebf *** empty log message ***
sr
parents: 5216
diff changeset
  9503
    pixelValue := aColorOrPixelValue.
e9ab91666ebf *** empty log message ***
sr
parents: 5216
diff changeset
  9504
    pixelValue isInteger ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9505
        pixelValue := self valueFromColor:aColorOrPixelValue
5235
e9ab91666ebf *** empty log message ***
sr
parents: 5216
diff changeset
  9506
    ].
e9ab91666ebf *** empty log message ***
sr
parents: 5216
diff changeset
  9507
    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
  9508
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9509
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9510
     |i|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9511
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9512
     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
  9513
     i photometric:#blackIs0.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9514
     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
  9515
     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
  9516
     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
  9517
     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
  9518
     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
  9519
     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
  9520
     i inspect.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9521
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9522
!
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9523
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9524
drawLineFrom:startPoint to:endPoint withValue:aPixelValueOrNil
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9525
    "draw a line with some pixel value.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9526
     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
  9527
     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
  9528
     (such as the HumanReadableImageGenerator).
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9529
     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
  9530
     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
  9531
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9532
    |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
  9533
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9534
    x0 := startPoint x.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9535
    y0 := startPoint y.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9536
    x1 := endPoint x.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9537
    y1 := endPoint y.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9538
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9539
    steep := (y1 - y0) abs > (x1 - x0) abs.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9540
    steep ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9541
        t := x0. x0 := y0. y0 := t.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9542
        t := x1. x1 := y1. y1 := t.
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9543
    ].
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9544
    x0 > x1 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9545
        t := x0. x0 := x1. x1 := t.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9546
        t := y0. y0 := y1. y1 := t.
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9547
    ].
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9548
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9549
    deltax := x1 - x0.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9550
    deltay := (y1 - y0) abs.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9551
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9552
    deltax == 0 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9553
        y0 to: y1 do:[:y |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9554
            self atImageAndMask:x0@y putValue:aPixelValueOrNil.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9555
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9556
        ^ self.
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9557
    ].
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9558
    deltay == 0 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9559
        x0 to: x1 do:[:x |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9560
            self atImageAndMask:x@y0 putValue:aPixelValueOrNil.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9561
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9562
        ^ self.
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9563
    ].
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9564
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9565
    error := 0.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9566
    deltaerr := deltay / deltax.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9567
    y := y0.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9568
    y0 < y1 ifTrue:[ ystep := 1 ] ifFalse:[ ystep := -1 ].
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9569
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9570
    x0 to: x1 do:[:x |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9571
        steep ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9572
            self atImageAndMask:y@x putValue:aPixelValueOrNil.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9573
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9574
            self atImageAndMask:x@y putValue:aPixelValueOrNil.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9575
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9576
        error := error + deltaerr.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9577
        error >= 0.5 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9578
            y := y + ystep.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9579
            error := error - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9580
        ]
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9581
    ].
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9582
    self release. "/ device-image is no longer valid
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9583
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9584
    "
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9585
     |i|
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9586
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9587
     i := Depth1Image extent:100@100 depth:1 palette:nil.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9588
     i photometric:#blackIs0.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9589
     i drawLineFrom:5@5 to:94@5 withColor:1.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9590
     i drawLineFrom:94@5 to:94@94 withColor:1.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9591
     i drawLineFrom:94@94 to:5@94 withColor:1.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9592
     i drawLineFrom:5@94 to:5@5 withColor:1.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9593
     i drawLineFrom:10@10 to:90@90 withColor:1.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9594
     i drawLineFrom:90@10 to:10@90 withColor:1.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9595
     i inspect.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9596
    "
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9597
!
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9598
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9599
drawRectangle: aRectangle withColor:aColor
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9600
    "draw a rectangle with some pixel value.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9601
     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
  9602
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9603
    self drawRectangle:aRectangle withValue:(self valueFromColor:aColor)
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9604
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9605
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9606
     |i|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9607
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9608
     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
  9609
     i photometric:#blackIs0.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9610
     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
  9611
     i inspect.
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
!
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9614
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9615
drawRectangle: aRectangle withValue:aPixelValueOrNil
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9616
    "draw a rectangle with some pixel value.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9617
     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
  9618
     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
  9619
     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
  9620
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9621
    |xI "{ Class: SmallInteger }"
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9622
     yI "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9623
     wI "{ Class: SmallInteger }"
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9624
     hI "{ Class: SmallInteger }"|
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9625
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9626
    xI := aRectangle left.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9627
    yI := aRectangle top.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9628
    wI := aRectangle width.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9629
    hI := aRectangle height.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9630
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9631
    xI to:xI+wI-1 do:[:xRun|
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9632
        self atImageAndMask: xRun@yI put:aPixelValueOrNil.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9633
        self atImageAndMask: xRun@(yI+hI-1) put:aPixelValueOrNil
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9634
    ].
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9635
    yI+1 to:yI+hI-2 do:[:yRun|
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9636
        self atImageAndMask: xI@yRun put:aPixelValueOrNil.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9637
        self atImageAndMask: xI+wI-1@yRun put:aPixelValueOrNil
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9638
    ].
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9639
    self release. "/ device-image is no longer valid
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9640
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9641
    "
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9642
     |i|
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9643
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9644
     i := Depth1Image extent:100@100 depth:1 palette:nil.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9645
     i photometric:#blackIs0.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9646
     i drawRectangle:(10@10 corner:90@90) withColor:1.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9647
     i inspect.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9648
    "
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9649
!
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9650
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  9651
fillAntiAliasedArc:origin radius:r from:startAngle angle:angle withColor:aColor colorDictionary:colorDictionary blendStart:blendStart
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9652
    "draw a circle with some pixel value.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9653
     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
  9654
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9655
    |tempForm wI "{ Class: SmallInteger }"
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9656
     hI "{ Class: SmallInteger }"
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9657
     colorValue tempImage|
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9658
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9659
    wI := self width.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9660
    hI := self height.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9661
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9662
    tempForm := Form width:wI height:hI depth:1 onDevice:Screen current.
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  9663
    tempForm
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9664
        paint:(Color colorId:1) on:(Color colorId:0);
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9665
        clear.
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9666
    tempForm fillArc:origin radius:r from:startAngle angle:angle.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9667
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9668
    colorValue := self valueFromColor:aColor.
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9669
    tempImage := tempForm asImage.
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9670
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9671
    0 to:hI-1 do:[:yRun|
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9672
        0 to:wI-1 do:[:xRun|
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9673
            (tempImage pixelAtX:xRun y:yRun) == 1 ifTrue:[
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9674
                self atImageAndMask:xRun@yRun putValue:colorValue.
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9675
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9676
                #(left right) do:[:aHorizontal |
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9677
                    #(top bottom) do:[:aVertical |
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9678
                        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
  9679
                        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
  9680
                    ].
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9681
                ].
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9682
            ].
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9683
        ].
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9684
    ].
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9685
    tempForm destroy.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9686
    tempImage close.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9687
    self release. "/ device-image is no longer valid
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9688
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9689
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9690
    "
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9691
        |colorMap aaImgArray|
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9692
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9693
        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
  9694
7484
ac97ca090d0c #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 7483
diff changeset
  9695
        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
  9696
        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
  9697
            colorDictionary:aaImgArray first
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9698
            blendStart:aaImgArray second.
7484
ac97ca090d0c #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 7483
diff changeset
  9699
        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
  9700
            colorDictionary:aaImgArray first
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9701
            blendStart:aaImgArray second.
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9702
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9703
        aaImgArray last inspect.
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9704
    "
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9705
!
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9706
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9707
fillArc:origin radius:r from:startAngle angle:angle withColor:aColorOrIndex
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9708
    "draw a circle with some pixel value.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9709
     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
  9710
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9711
    |tempForm tempImage
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9712
     wI "{ Class: SmallInteger }"
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9713
     hI "{ Class: SmallInteger }"
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9714
     colorValue|
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9715
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9716
    wI := self width.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9717
    hI := self height.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9718
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9719
    tempForm := Form width:wI height:hI depth:1 onDevice:Screen current.
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  9720
    tempForm
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9721
        paint:(Color colorId:1) on:(Color colorId:0);
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9722
        clear.
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9723
    tempForm fillArc:origin radius:r from:startAngle angle:angle.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9724
4997
15d53562d4e8 changed #fillArc:radius:from:angle:withColor:
sr
parents: 4996
diff changeset
  9725
    aColorOrIndex isInteger ifTrue:[
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9726
        colorValue := aColorOrIndex.
4997
15d53562d4e8 changed #fillArc:radius:from:angle:withColor:
sr
parents: 4996
diff changeset
  9727
    ] ifFalse:[
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9728
        colorValue := self valueFromColor:aColorOrIndex.
4997
15d53562d4e8 changed #fillArc:radius:from:angle:withColor:
sr
parents: 4996
diff changeset
  9729
    ].
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9730
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9731
    tempImage := tempForm asImage.
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9732
    0 to:hI-1 do:[:yRun|
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9733
        0 to:wI-1 do:[:xRun|
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9734
            (tempImage pixelAtX:xRun y:yRun) == 1 ifTrue:[
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9735
                self atImageAndMask:xRun@yRun putValue:colorValue.
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9736
            ].
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9737
        ].
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9738
    ].
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9739
    tempForm destroy.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9740
    tempImage close.
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9741
    self release. "/ device-image is no longer valid
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9742
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9743
    "
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9744
     |cm i|
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9745
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9746
     cm :=  Array with:Color white with:Color black with:Color red with:Color blue.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9747
7484
ac97ca090d0c #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 7483
diff changeset
  9748
     i := Depth8Image extent:200@200 depth:8 palette:cm.
ac97ca090d0c #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 7483
diff changeset
  9749
     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
  9750
     i fillArc:100@100 radius:80 from:90 angle:270 withColor:Color blue.
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9751
     i inspect.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9752
    "
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9753
!
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9754
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9755
fillEllipse:aRectangle withColor:aColor
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9756
    "draw a circle with some pixel value.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9757
     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
  9758
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9759
    self fillEllipse:aRectangle withValue:(self valueFromColor:aColor)
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9760
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9761
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9762
     |cm i|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9763
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9764
     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
  9765
7484
ac97ca090d0c #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 7483
diff changeset
  9766
     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
  9767
     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
  9768
     i inspect.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9769
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9770
!
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9771
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9772
fillEllipse:aRectangle withValue:aPixelValueOrNil
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9773
    "draw a circle with some pixel value.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9774
     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
  9775
     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
  9776
     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
  9777
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9778
    |tempForm xI "{ Class: SmallInteger }"
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9779
     yI "{ Class: SmallInteger }"
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9780
     wI "{ Class: SmallInteger }"
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9781
     hI "{ Class: SmallInteger }" tempImage|
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9782
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9783
    wI := aRectangle width.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9784
    hI := aRectangle height.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9785
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9786
    tempForm := Form width:wI height:hI depth:1 onDevice:Screen current.
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
  9787
    tempForm
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9788
        paint:(Color colorId:1) on:(Color colorId:0);
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9789
        clear.
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9790
    tempForm fillArcIn:(0@0 extent:wI@hI) from:0 angle:360.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9791
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9792
    xI := aRectangle left.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9793
    yI := aRectangle top.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9794
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9795
    tempImage := tempForm asImage.
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9796
    0 to:hI-1 do:[:yRun|
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9797
        0 to:wI-1 do:[:xRun|
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9798
            (tempImage pixelAtX:xRun y:yRun) == 1 ifTrue:[
7480
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9799
                self atImageAndMask:(xI+xRun)@(yI+yRun) putValue:aPixelValueOrNil.
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9800
            ].
c5f7b4f01ed9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7404
diff changeset
  9801
        ].
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9802
    ].
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9803
    tempForm destroy.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
  9804
    tempImage close.
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9805
    self release. "/ device-image is no longer valid
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9806
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9807
    "
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9808
     |cm i|
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9809
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9810
     cm :=  Array with:Color white with:Color black with:Color red.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9811
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9812
     i := Depth8Image extent:300@400 depth:8 palette:cm.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9813
     i fillEllipse:(0@0 corner:80@100) withColor:Color red.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9814
     i inspect.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9815
    "
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9816
!
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9817
4995
3a5cb7a57b0b changed #fillRectangle:aRectangle withColor:aColor
sr
parents: 4994
diff changeset
  9818
fillRectangle:aRectangle withColor:aColor
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9819
    self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9820
        fillRectangle:aRectangle
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9821
        withValue:(self valueFromColor:aColor)
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9822
!
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9823
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9824
fillRectangle:aRectangle withValue:aPixelValueOrNil
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9825
    "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
  9826
     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
  9827
     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
  9828
     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
  9829
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9830
    self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9831
        fillRectangleX:aRectangle left y:aRectangle top
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9832
        width:aRectangle width height:aRectangle height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9833
        withValue:aPixelValueOrNil
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9834
!
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9835
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9836
fillRectangleX:x y:y width:w height:h with:aColor
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9837
    "fill a rectangular area with a aColor"
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9838
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9839
    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
  9840
!
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  9841
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9842
fillRectangleX:x y:y width:w height:h withValue:aPixelValueOrNil
1630
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  9843
    "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
  9844
     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
  9845
     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
  9846
     otherwise to 1. (used by the bitmap editor)"
1630
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  9847
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  9848
    |xI "{ Class: SmallInteger }"
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9849
     yI "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9850
     wI "{ Class: SmallInteger }"
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9851
     hI "{ Class: SmallInteger }"
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9852
     p|
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9853
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9854
    xI := x.
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9855
    yI := y.
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9856
    wI := w.
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9857
    hI := h.
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9858
    p := Point new.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9859
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9860
    yI to:yI+hI-1 do:[:yRun |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9861
        xI to:xI+wI-1 do:[:xRun |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9862
            p x:xRun y:yRun.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9863
            self atImageAndMask:p putValue:aPixelValueOrNil.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9864
        ]
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9865
    ].
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9866
    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
  9867
1630
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  9868
    "Created: 22.4.1997 / 14:02:14 / cg"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9869
    "Modified: 24.4.1997 / 17:24:58 / cg"
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9870
!
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9871
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9872
floodFillAt: aPoint withColor: aColor
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9873
    "fill a area with aColor like a flood up to surrounded pixels having different colors.
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9874
     By using #atImageAndMask:put: it also works on images with mono masks."
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9875
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9876
    self floodFillAt:aPoint withValue:(self valueFromColor:aColor)
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9877
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9878
"/    |surroundingPixelsOfDo detectedPixel processPixelToFill
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9879
"/     allDetectedPixelCoordinates enumerateDetectedPixelsAndDo
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9880
"/     toDo idx pixel w h|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9881
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9882
"/    w := self width.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9883
"/    h := self height.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9884
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9885
"/    surroundingPixelsOfDo :=
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9886
"/        [:pX :pY :fn |
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9887
"/            |nX nY|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9888
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9889
"/            nX := pX + 1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9890
"/            nY := pY + 1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9891
"/            (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
  9892
"/            (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
  9893
"/            (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
  9894
"/            (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
  9895
"/        ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9896
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9897
"/    enumerateDetectedPixelsAndDo :=
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9898
"/        [:detectedPixels :action |
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9899
"/            |idx|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9900
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9901
"/            idx := 1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9902
"/            0 to:h-1 do:[:y |
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9903
"/                0 to:w-1 do:[:x |
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9904
"/                    (detectedPixels at:idx) ifTrue:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9905
"/                        action value:x value:y
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9906
"/                    ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9907
"/                    idx := idx + 1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9908
"/                ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9909
"/            ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9910
"/        ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9911
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9912
"/    processPixelToFill := [:spX :spY |
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9913
"/            |sp idx|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9914
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9915
"/            ((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
  9916
"/            ifTrue: [
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9917
"/                idx := 1 + spX + (spY * w).
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9918
"/                (allDetectedPixelCoordinates at:idx) ifFalse:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9919
"/                    allDetectedPixelCoordinates at:idx put:true.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9920
"/                    toDo add:spX @ spY.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9921
"/                ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9922
"/            ]
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
"/    (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
  9926
"/        allDetectedPixelCoordinates := mask floodFillAt: aPoint withColor: Color white.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9927
"/        enumerateDetectedPixelsAndDo
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9928
"/                value:allDetectedPixelCoordinates
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9929
"/                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
  9930
"/        ^ allDetectedPixelCoordinates
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9931
"/    ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9932
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9933
"/    detectedPixel := self pixelAt: aPoint.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9934
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9935
"/    allDetectedPixelCoordinates := BooleanArray new:(w * h).
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9936
"/    toDo := OrderedCollection new:1000.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9937
"/    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
  9938
"/    toDo add:aPoint.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9939
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9940
"/    [toDo notEmpty] whileTrue:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9941
"/        |p|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9942
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9943
"/        p := toDo removeFirst.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9944
"/        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
  9945
"/    ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9946
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9947
"/    idx := 1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9948
"/    aColor redByte notNil ifTrue:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9949
"/        pixel := self valueFromColor:aColor.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9950
"/    ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9951
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9952
"/    pixel isNil ifTrue:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9953
"/        enumerateDetectedPixelsAndDo
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9954
"/                value:allDetectedPixelCoordinates
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9955
"/                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
  9956
"/    ] ifFalse:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9957
"/        enumerateDetectedPixelsAndDo
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9958
"/                value:allDetectedPixelCoordinates
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9959
"/                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
  9960
"/    ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9961
"/    ^ allDetectedPixelCoordinates
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9962
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9963
    "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
  9964
!
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9965
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9966
floodFillAt:aPoint withValue:aPixelValueOrNil
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9967
    "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
  9968
     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
  9969
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9970
    |surroundingPixelsOfDo detectedPixel detectedMask processPixelToFill
3861
e9cbd4ec6020 flood fill with mask fixed
Claus Gittinger <cg@exept.de>
parents: 3860
diff changeset
  9971
     allDetectedPixelCoordinates enumerateDetectedPixelsAndDo
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9972
     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
  9973
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  9974
    w := self width.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  9975
    h := self height.
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9976
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9977
    surroundingPixelsOfDo :=
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9978
        [:pX :pY :fn |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9979
            |nX nY|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9980
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9981
            nX := pX + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9982
            nY := pY + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9983
            (nY < h) ifTrue: [fn value:pX value:nY].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9984
            (pY > 0) ifTrue: [fn value:pX value:(pY - 1)].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9985
            (nX < w) ifTrue: [fn value:nX value:pY].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9986
            (pX > 0) ifTrue: [fn value:(pX - 1) value:pY].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9987
        ].
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9988
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9989
    enumerateDetectedPixelsAndDo :=
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9990
        [:detectedPixels :action |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9991
            |idx|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9992
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9993
            idx := 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9994
            0 to:h-1 do:[:y |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9995
                0 to:w-1 do:[:x |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9996
                    (detectedPixels at:idx) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9997
                        action value:x value:y
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9998
                    ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  9999
                    idx := idx + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10000
                ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10001
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10002
        ].
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10003
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10004
    processPixelToFill :=
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10005
        [:spX :spY |
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 10006
            |samePixel idx|
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10007
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10008
            mask isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10009
                samePixel := (self pixelAtX:spX y:spY) == detectedPixel
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10010
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10011
                detectedMask == 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10012
                    samePixel := (mask pixelAtX:spX y:spY) == 0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10013
                ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10014
                    samePixel := ((self pixelAtX:spX y:spY) == detectedPixel)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10015
                                 and:[ (mask pixelAtX:spX y:spY) == detectedMask ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10016
                ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10017
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10018
            samePixel ifTrue: [
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10019
                idx := 1 + spX + (spY * w).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10020
                (allDetectedPixelCoordinates at:idx) ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10021
                    allDetectedPixelCoordinates at:idx put:true.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10022
                    toDo add:spX @ spY.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10023
                ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10024
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10025
        ].
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10026
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10027
"/    (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
 10028
"/        allDetectedPixelCoordinates := mask floodFillAt: aPoint withColor: Color white.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10029
"/        enumerateDetectedPixelsAndDo
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10030
"/                value:allDetectedPixelCoordinates
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10031
"/                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
 10032
"/        ^ allDetectedPixelCoordinates
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10033
"/    ].
3759
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
 10034
2205
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
 10035
    detectedPixel := self pixelAt: aPoint.
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10036
    mask isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10037
        detectedMask := 1
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10038
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10039
        detectedMask := mask pixelAt: aPoint.
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10040
    ].
4420
6b8505b72ae6 flood-filling of 24-bit images
Claus Gittinger <cg@exept.de>
parents: 4418
diff changeset
 10041
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10042
    allDetectedPixelCoordinates := BooleanArray new:(w * h).
3759
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
 10043
    toDo := OrderedCollection new:1000.
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10044
    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
 10045
    toDo add:aPoint.
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
 10046
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
 10047
    [toDo notEmpty] whileTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10048
        |p|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10049
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10050
        p := toDo removeLast.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10051
        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
 10052
    ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10053
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10054
    aPixelValueOrNil isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10055
        drawAction := [:x :y |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10056
                               mask pixelAtX:x y:y put:0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10057
                               self pixelAtX:x y:y put:0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10058
                      ].
3805
d87c919fb2a7 oops - care for filling a mask
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
 10059
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10060
        drawAction := [:x :y |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10061
                                mask notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10062
                                    mask pixelAtX:x y:y put:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10063
                                ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10064
                                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
 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
    enumerateDetectedPixelsAndDo
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10068
        value:allDetectedPixelCoordinates
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10069
        value:drawAction.
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
 10070
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
 10071
    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
 10072
    ^ allDetectedPixelCoordinates
2205
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
 10073
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 10074
    "Modified: / 29-07-1998 / 03:09:16 / cg"
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 10075
    "Modified (format): / 30-01-2017 / 20:57:36 / stefan"
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
 10076
!
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
 10077
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
 10078
rectangle: aRectangle withColor:aColor
5216
f7ec910cfce1 Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 5200
diff changeset
 10079
    <resource: #obsolete>
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
 10080
    "draw a rectangle with some pixel value.
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
 10081
    By using #atImageAndMask:put: it also works on images with mono masks."
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
 10082
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
 10083
    self obsoleteMethodWarning.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
 10084
    self drawRectangle: aRectangle withColor:aColor
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
 10085
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
 10086
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 10087
! !
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 10088
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10089
!Image methodsFor:'enumerating'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10090
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10091
atY:y from:x1 to:x2 do:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10092
    "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
 10093
     The block is passed the color at each pixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10094
     The code here provides a generic and slow implementation, and
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10095
     should be redefined in concrete subclasses, to avoid some processing
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10096
     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
 10097
     and also the color allocation)."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10098
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
 10099
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
 10100
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10101
    self obsoleteMethodWarning:'use #colorsAtY:from:to:do:'.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10102
    self colorsAtY:y from:x1 to:x2 do:aBlock
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10103
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10104
    "Modified: 7.6.1996 / 19:13:30 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10105
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10106
5143
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
 10107
colorsAtX:x from:y1 to:y2 do:aBlock
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
 10108
    "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
 10109
     The block is passed the color at each pixel.
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
 10110
     The code here provides a generic and slow implementation, and
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
 10111
     should be redefined in concrete subclasses, to avoid some processing
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
 10112
     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
 10113
     and also the color allocation)."
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
 10114
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
 10115
    |yStart "{Class: SmallInteger }"
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
 10116
     yEnd   "{Class: SmallInteger }"|
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
 10117
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
 10118
    yStart := y1.
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
 10119
    yEnd := y2.
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
 10120
    yStart to:yEnd do:[:yRun |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10121
        aBlock value:yRun value:(self colorAtX:x y:yRun)
5143
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
 10122
    ]
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
 10123
!
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
 10124
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10125
colorsAtY:y from:x1 to:x2 do:aBlock
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10126
    "perform aBlock for each pixel from x1 to x2 in row y.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10127
     The block is passed the color at each pixel.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10128
     The code here provides a generic and slow implementation, and
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10129
     should be redefined in concrete subclasses, to avoid some processing
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10130
     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
 10131
     and also the color allocation)."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10132
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10133
    |xStart "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10134
     xEnd   "{Class: SmallInteger }"|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10135
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10136
    xStart := x1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10137
    xEnd := x2.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10138
    xStart to:xEnd do:[:xRun |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10139
        aBlock value:xRun value:(self colorAtX:xRun y:y)
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10140
    ]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10141
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
 10142
    "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
 10143
    "Modified: / 30.9.1998 / 22:14:16 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10144
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10145
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10146
colorsFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10147
    "perform aBlock for each color in a rectangular area of the image.
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 10148
     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
 10149
     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
 10150
     The code here provides a generic and slow implementation, and
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10151
     should be redefined in concrete subclasses, to avoid some processing
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10152
     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
 10153
     and especially, the color allocations)."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10154
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 10155
    |yS "{Class: SmallInteger }"
7595
c77d718d3d94 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7573
diff changeset
 10156
     yE "{Class: SmallInteger }"|
942
5e45da3c19d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
 10157
5e45da3c19d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
 10158
    yS := yStart.
5e45da3c19d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
 10159
    yE := yEnd.
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 10160
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10161
    yS to:yE do:[:yRun |
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 10162
        self colorsAtY:yRun from:xStart to:xEnd do:[:xRun :color |
7595
c77d718d3d94 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7573
diff changeset
 10163
            aBlock value:xRun value:yRun value:color
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 10164
        ]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10165
    ]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10166
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 10167
    "Modified: 11.7.1996 / 19:50:47 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10168
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10169
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10170
valueAtY:y from:x1 to:x2 do:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10171
    "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
 10172
     Obsolete - remains for backward compatibility."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10173
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
 10174
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
 10175
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10176
    self obsoleteMethodWarning:'use #valuesAtY:from:to:do:'.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10177
    self valuesAtY:y from:x1 to:x2 do:aBlock
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10178
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10179
    "Modified: 7.6.1996 / 19:11:06 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10180
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10181
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10182
valuesAtY:y from:x1 to:x2 do:aBlock
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10183
    "WARNING: for now, this enumerates pixel values
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10184
     (backward compatibility with ST/X)
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10185
     In the future, this will enumerate colors
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10186
     Use #pixelAtT:from:to:do: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10187
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10188
     perform aBlock for each pixelValue from x1 to x2 in row y.
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 10189
     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
 10190
     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
 10191
     (see also Image>>atY:from:to:do:).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10192
     The code here provides a generic and slow implementation, and
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10193
     should be redefined in concrete subclasses, to avoid some processing
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10194
     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
 10195
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10196
    |xStart "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10197
     xEnd   "{Class: SmallInteger }"|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10198
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10199
    xStart := x1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10200
    xEnd := x2.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10201
    xStart to:xEnd do:[:xRun |
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 10202
        aBlock value:xRun value:(self pixelAtX:xRun y:y)
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10203
    ]
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10204
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10205
    "Created: 7.6.1996 / 19:09:51 / cg"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10206
    "Modified: 24.4.1997 / 16:55:38 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10207
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10208
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10209
valuesFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10210
    "perform aBlock for each pixelValue in a rectangular area of the image.
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 10211
     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
 10212
     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
 10213
     The code here provides a generic and slow implementation, and
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10214
     should be redefined in concrete subclasses, to avoid some processing
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10215
     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
 10216
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 10217
    |yS "{Class: SmallInteger }"
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 10218
     yE "{Class: SmallInteger }"|
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 10219
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 10220
    yS := yStart.
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 10221
    yE := yEnd.
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 10222
    yS to:yE do:[:yRun |
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 10223
        self valuesAtY:yRun from:xStart to:xEnd do:[:xRun :pixel |
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 10224
            aBlock value:xRun value:yRun value:pixel
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 10225
        ]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10226
    ]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10227
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 10228
    "Modified: / 07-06-1996 / 19:09:29 / cg"
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 10229
    "Modified: / 31-01-2017 / 14:46:26 / stefan"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 10230
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
 10231
3613
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10232
!Image methodsFor:'finalization'!
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10233
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10234
finalizationLobby
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10235
    "answer the registry used for finalization.
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10236
     Images have their own Registry"
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10237
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10238
    ^ Lobby
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10239
!
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10240
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10241
finalize
7483
0690072b1c56 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 7482
diff changeset
 10242
    "some Image has been collected - nothing to do.
0690072b1c56 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 7482
diff changeset
 10243
0690072b1c56 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 7482
diff changeset
 10244
     The only reason we register Images is, that we can release
0690072b1c56 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 7482
diff changeset
 10245
     their device resources when a GraphicsDevice is closed.
0690072b1c56 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 7482
diff changeset
 10246
0690072b1c56 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 7482
diff changeset
 10247
     (#releaseResourcesOnDevice: at class side)."
3613
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10248
! !
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10249
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 10250
!Image methodsFor:'image manipulations'!
48194c26a46c Initial revision
claus
parents:
diff changeset
 10251
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10252
applyPixelValuesTo:pixelFunctionBlock in:aRectangle into:newImage
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 10253
    "helper for withPixelFunctionAppliedToValues:
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 10254
     enumerate pixelValues and evaluate the block for each.
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10255
     Could be redefined by subclasses for better performance."
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10256
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10257
    |w   "{Class: SmallInteger }"
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10258
     h   "{Class: SmallInteger }"
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10259
     x0  "{Class: SmallInteger }"
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10260
     y0  "{Class: SmallInteger }"
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10261
     y   "{Class: SmallInteger }"
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10262
     newPixel newPixelRow pixelRow|
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10263
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10264
    x0 := aRectangle left.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10265
    y0 := aRectangle top.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10266
    w := aRectangle width.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10267
    h := aRectangle height.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10268
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10269
    newPixelRow := Array new:w.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10270
    pixelRow := self pixelArraySpecies new:width.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10271
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10272
    (x0 = 0 and:[w = self width]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10273
        "/ slightly faster
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10274
        y := y0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10275
        h timesRepeat:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10276
            self rowAt:y into:pixelRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10277
            1 to:w do:[:runCol |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10278
                newPixel := pixelFunctionBlock
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10279
                                value:self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10280
                                value:(pixelRow at:runCol)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10281
                                value:(runCol-1)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10282
                                value:y.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10283
                newPixelRow at:runCol put:newPixel.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10284
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10285
            newImage rowAt:y putAll:newPixelRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10286
            y := y + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10287
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10288
        ^ self.
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10289
    ].
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10290
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10291
    y := y0.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10292
    h timesRepeat:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10293
        self rowAt:y into:pixelRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10294
        1 to:w do:[:runCol |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10295
            newPixel := pixelFunctionBlock
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10296
                            value:self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10297
                            value:(pixelRow at:runCol+x0)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10298
                            value:(runCol+x0-1)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10299
                            value:y.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10300
            newPixelRow at:runCol put:newPixel.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10301
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10302
        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
 10303
        newImage rowAt:y putAll:pixelRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10304
        y := y + 1.
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10305
    ].
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10306
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10307
    "Modified: 24.4.1997 / 16:18:31 / cg"
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10308
!
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10309
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10310
applyPixelValuesTo:pixelFunctionBlock into:newImage
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10311
    "helper for withPixelFunctionAppliedToValues:
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10312
     enumerate pixelValues and evaluate the block for each."
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10313
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10314
    ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10315
        applyPixelValuesTo:pixelFunctionBlock
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10316
        in:(0@0 corner:width@height)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10317
        into:newImage
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10318
!
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10319
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10320
blendWith:aColor
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10321
    "return a new image which is blended with some color.
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10322
     The receiver must be a palette image (currently).
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10323
     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
 10324
     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
 10325
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10326
     ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10327
        copyWithColorMapProcessing:[:clr | clr blendWith:aColor]
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10328
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10329
    "
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10330
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10331
     ((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
 10332
     ((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
 10333
     ((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
 10334
    "
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10335
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10336
    "Modified: 24.4.1997 / 18:31:23 / cg"
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10337
!
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10338
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10339
colorMapProcessing:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10340
    "a helper for all kinds of colormap manipulations.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10341
     The argument, aBlock is called for every colormap entry,
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10342
     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
 10343
     This will fail for non-palette images.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10344
     See examples in Image>>copyWithColorMapProcessing:"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10345
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10346
    |nColors "{ Class: SmallInteger }"|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10347
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10348
    colorMap isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10349
        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
 10350
            self colorAtX:x y:y put:(aBlock value:clr)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10351
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10352
        ^ self
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10353
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10354
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10355
    nColors := colorMap size.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10356
    1 to:nColors do:[:index |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10357
        |clr|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10358
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10359
        clr := colorMap at:index.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10360
        clr notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10361
            colorMap at:index put:(aBlock value:clr)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10362
        ]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10363
    ]
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10364
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10365
    "Modified: 23.4.1996 / 11:13:55 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10366
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10367
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10368
copyWithColorMapProcessing:aBlock
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10369
    "a helper to create & return new images based on the receiver with
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10370
     some colorMap processing. The receiver is copied, and the copied images
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10371
     colormap is modified by replacing entries with the result of the processing block,
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10372
     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
 10373
     a color.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10374
     CAVEAT: this only works with palette images (i.e. not for rgb or greyScale)"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10375
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10376
    |newImage|
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10377
4414
2c0f2ca53156 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
 10378
    self colorMap isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10379
        ^ self withPixelFunctionApplied:[:orig :clr :x :y | aBlock  value:clr]
4414
2c0f2ca53156 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
 10380
"/        self error:'no colormap in image'.
2c0f2ca53156 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
 10381
"/        ^ nil
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10382
    ].
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10383
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10384
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10385
     the code below manipulates the colormap.
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10386
     For non-palette images, special code is required
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10387
    "
4414
2c0f2ca53156 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
 10388
    newImage := self copy.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10389
    newImage colorMapProcessing:aBlock.
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10390
    ^ newImage
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10391
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10392
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10393
     leave red component only:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10394
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10395
     (Image fromFile:'goodies/bitmaps/gifImages/claus.gif')
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10396
        copyWithColorMapProcessing:[:clr | Color red:(clr red) green:0 blue:0]
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10397
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10398
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10399
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10400
     make it reddish:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10401
6653
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10402
     |img imgYellow imgGreen imgBlue|
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10403
     img := (Image fromFile:'../../../expeccoNET/server/data/images/styles/eXept/defects.gif').
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10404
     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
 10405
     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
 10406
     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
 10407
     imgBlue
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10408
    "
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10409
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10410
    "
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10411
     make it reddish:
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10412
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10413
     (Image fromFile:'../../goodies/bitmaps/gifImages/claus.gif')
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10414
        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
 10415
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10416
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10417
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10418
     invert:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10419
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10420
     (Image fromFile:'bitmaps/gifImages/claus.gif')
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10421
        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
 10422
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10423
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10424
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10425
     lighter:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10426
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10427
     (Image fromFile:'bitmaps/gifImages/claus.gif')
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10428
        copyWithColorMapProcessing:[:clr | |r g b|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10429
                                                r := clr red.  g := clr green.  b := clr blue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10430
                                                Color red:(r + (100-r//2))
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10431
                                                      green:(g + (100-g//2))
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10432
                                                      blue:(b + (100-b//2))]
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10433
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10434
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10435
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10436
     darker:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10437
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10438
     (Image fromFile:'bitmaps/gifImages/claus.gif')
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10439
        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
 10440
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10441
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10442
    "Modified: 24.4.1997 / 18:28:05 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10443
!
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10444
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10445
createMask
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10446
    |maskArray bytesPerMaskRow|
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10447
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10448
    bytesPerMaskRow := (width+7) // 8.
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10449
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10450
    maskArray := ByteArray new:(bytesPerMaskRow * height) withAll:2r11111111.
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10451
    mask := ImageMask width:width height:height fromArray:maskArray.
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10452
    ^ mask
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10453
!
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10454
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10455
darkened
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10456
    "return a new image which is slightly darker than the receiver.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10457
     The receiver must be a palette image (currently).
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10458
     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
 10459
     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
 10460
5655
37bd5c7eb765 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 5643
diff changeset
 10461
     ^ self copyWithColorMapProcessing:[:clr | clr darkened]
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10462
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10463
    "
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10464
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10465
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') darkened inspect
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10466
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10467
5655
37bd5c7eb765 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 5643
diff changeset
 10468
    "Modified: / 24-11-2010 / 11:06:58 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10469
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10470
7534
0b7e23635791 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7529
diff changeset
 10471
easyRotateBitsInto:destinationImage angle:degrees
7523
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10472
    "helper for rotation - does the actual pixel shuffling.
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10473
     by degrees clockwise. Here, only 90, 180 and 270 degrees
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10474
     are implemented. Hard angles are done in #hardRotate:.
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10475
     The code here is depth-independent (but not too fast);
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10476
     can be redefined in subclasses for more performance"
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10477
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10478
    |w  "{Class: SmallInteger }"
7529
5f77a718b7bd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7523
diff changeset
 10479
     h  "{Class: SmallInteger }" 
5f77a718b7bd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7523
diff changeset
 10480
     pixelMover|
7523
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10481
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10482
    w := width - 1.
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10483
    h := height - 1.
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10484
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10485
    degrees = 90 ifTrue:[
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10486
        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
 10487
    ] ifFalse:[
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10488
        degrees = 180 ifTrue:[
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10489
            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
 10490
        ] ifFalse:[
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10491
            degrees = 270 ifTrue:[
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10492
                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
 10493
            ] ifFalse:[
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10494
                ^ self
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10495
            ].
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10496
        ].
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10497
    ].    
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10498
    self valuesFromX:0 y:0 toX:w y:h do:pixelMover.
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10499
    ^ self.
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10500
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10501
    "
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10502
     |i|
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10503
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10504
     i := Image fromFile:'../../goodies/bitmaps/gifImages/claus.gif'.
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10505
     i inspect.
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10506
     (i rotated:45) inspect.
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10507
     (i rotated:90) inspect.
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10508
     (i rotated:180) inspect.
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10509
     (i rotated:270) inspect.
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10510
    "
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10511
    "
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10512
     |i|
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10513
     i := Image fromFile:'../../goodies/bitmaps/gifImages/claus.gif'.
7529
5f77a718b7bd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7523
diff changeset
 10514
     i := Depth24Image fromImage:i.
7523
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10515
     Time millisecondsToRun:[ 100 timesRepeat:[ i rotated:90 ] ]
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10516
    "
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10517
    "
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10518
     |i|
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10519
     i := Image fromScreen.
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10520
     Time millisecondsToRun:[ 20 timesRepeat:[ i rotated:90 ] ]
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10521
    "
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10522
    
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10523
    "Created: 23.4.1997 / 14:36:45 / cg"
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10524
    "Modified: 24.4.1997 / 17:26:26 / cg"
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10525
!
f51843b46318 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7522
diff changeset
 10526
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10527
flipHorizontal
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10528
    "destructively inplace horizontal flip"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10529
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10530
    |h  "{Class: SmallInteger }"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10531
     pixelArray|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10532
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10533
    h := height - 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10534
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10535
    pixelArray := self pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10536
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10537
    0 to:h do:[:row |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10538
        self rowAt:row into:pixelArray.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10539
        pixelArray reverse.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10540
        self rowAt:row putAll:pixelArray.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10541
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10542
1386
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
 10543
    mask notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10544
        mask flipHorizontal
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10545
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10546
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10547
    "/ flush device info
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 10548
    self release
1386
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
 10549
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10550
    "
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10551
     (Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') flipHorizontal inspect
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10552
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10553
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10554
    "Modified: 24.4.1997 / 18:29:13 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10555
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10556
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10557
flipVertical
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10558
    "inplace vertical flip"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10559
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10560
    |h           "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10561
     bytesPerRow "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10562
     buffer
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10563
     indexLow    "{Class: SmallInteger }"
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 10564
     indexHi     "{Class: SmallInteger }"
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 10565
     bytes|
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 10566
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 10567
    bytes := self bits.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10568
    bytesPerRow := self bytesPerRow.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10569
    buffer := ByteArray new:bytesPerRow.
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
    h := height - 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10572
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10573
    indexLow := 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10574
    indexHi := bytesPerRow * h + 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10575
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10576
    0 to:(h // 2) do:[:row |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10577
        buffer replaceFrom:1 to:bytesPerRow with:bytes startingAt:indexLow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10578
        bytes replaceFrom:indexLow to:(indexLow + bytesPerRow - 1) with:bytes startingAt:indexHi.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10579
        bytes replaceFrom:indexHi to:(indexHi + bytesPerRow - 1) with:buffer startingAt:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10580
        indexLow := indexLow + bytesPerRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10581
        indexHi := indexHi - bytesPerRow.
1386
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
 10582
    ].
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
 10583
    mask notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10584
        mask flipVertical
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10585
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10586
    "flush device info"
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 10587
    self release
1386
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
 10588
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10589
    "
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10590
     (Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') flipVertical inspect
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10591
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10592
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10593
    "Modified: 24.4.1997 / 18:29:36 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10594
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10595
1739
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10596
hardAntiAliasedMagnifiedBy:scalePoint
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10597
    "return a new image magnified and antiAliased by scalePoint, aPoint.
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10598
     This converts into a depth24Image before doing the antiAlias-magnify.
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10599
     It is definitely slower than the non antiAliasing/integral magnification methods."
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10600
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10601
    ^ (Depth24Image fromImage:self)
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10602
        hardAntiAliasedMagnifiedBy:scalePoint
1739
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10603
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10604
    "Modified: 2.6.1997 / 13:19:57 / cg"
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10605
    "Created: 2.6.1997 / 15:53:34 / cg"
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10606
!
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10607
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10608
hardMagnifiedBy:scalePoint
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10609
    "return a new image magnified by scalePoint, aPoint.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10610
     This is the general magnification method, handling non-integral values.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10611
     It is slower than the integral magnification method."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10612
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10613
    |mX
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10614
     mY
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10615
     newWidth  "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10616
     newHeight "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10617
     w         "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10618
     h         "{ Class: SmallInteger }"
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 10619
     newImage newBits bitsPerPixel newBytesPerRow newMask
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10620
     value
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10621
     srcRow pixelArray|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10622
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10623
    mX := scalePoint x.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10624
    mY := scalePoint y.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10625
    ((mX < 0) or:[mY < 0]) ifTrue:[^ nil].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10626
    ((mX = 1) and:[mY = 1]) ifTrue:[^ self].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10627
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10628
    newWidth := (width * mX) truncated.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10629
    newHeight := (height * mY) truncated.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10630
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10631
    bitsPerPixel := self depth.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10632
    newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10633
    newBits := ByteArray uninitializedNew:(newBytesPerRow * newHeight).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10634
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 10635
    mask notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10636
        newMask := (mask magnifiedBy:scalePoint)
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 10637
    ].
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 10638
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10639
    newImage := self species new.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10640
    newImage
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10641
        width:newWidth
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10642
        height:newHeight
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10643
        photometric:photometric
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10644
        samplesPerPixel:samplesPerPixel
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10645
        bitsPerSample:bitsPerSample
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10646
        colorMap:colorMap copy
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10647
        bits:newBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10648
        mask:newMask.
905
228d503775d9 everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents: 904
diff changeset
 10649
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10650
    "walk over destination image fetching pixels from source image"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10651
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10652
    w := newWidth - 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10653
    h := newHeight - 1.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10654
    pixelArray := newImage pixelArraySpecies new:newWidth.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10655
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10656
    0 to:h do:[:row |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10657
        srcRow := (row // mY).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10658
        0 to:w do:[:col |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10659
            value := self pixelAtX:(col // mX) y:srcRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10660
            pixelArray at:(col+1) put:value.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10661
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10662
        newImage rowAt:row putAll:pixelArray.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10663
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10664
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10665
    ^ newImage
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10666
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10667
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10668
     |i|
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10669
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10670
     Time millisecondsToRun:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10671
         i := i hardMagnifiedBy:0.5@0.5
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10672
     ].
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10673
     i
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10674
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10675
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10676
    "Modified: 24.4.1997 / 18:30:24 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10677
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10678
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10679
hardRotated:degrees
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10680
    "return a new image from the old one, by rotating the image
4953
b5017336aa26 comment
Claus Gittinger <cg@exept.de>
parents: 4952
diff changeset
 10681
     degrees clockwise (around its center).
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10682
     Warning: the returned image will be larger than the original image."
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10683
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10684
    |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
 10685
     newImage
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10686
     newWidth  "{ Class: SmallInteger }"
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10687
     newHeight "{ Class: SmallInteger }"
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10688
     newBytesPerRow newBits
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10689
     blackPixel halfW halfH radians m t bad
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10690
     bytesPerRow myDepth maskBits
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10691
     pX pY srcX srcY pix nX nY
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10692
     sinRot cosRot sinPY cosPY|
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10693
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 10694
    radians := degrees degreesToRadians.
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 10695
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10696
    "/ placing the image at the origin,
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10697
    "/ compute the diagonal and angle.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10698
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10699
    p := (width - 1 / 2) @ (height - 1 / 2).
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10700
    r := p r.
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 10701
    a := p theta.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10702
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10703
    "/ add the rotation
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10704
    "/ (sight - subtract, we defined things clockwise ...
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10705
    "/  ... in contrast to point which thinks counter-clockwise)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10706
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 10707
    aN := a - radians.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10708
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10709
    "/ compute new corner points
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 10710
    p1 := Point r:r theta:aN.         "/ rotated topRight
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 10711
    p2 := Point r:r theta:aN-a-a.     "/ rotated bottomRight
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10712
    p3 := p1 * -1.                    "/ rotated bottomLeft
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10713
    p4 := p2 * -1.                    "/ rotated topLeft
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10714
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10715
    "/ compute the boundary of the new image
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10716
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10717
    maxX := minX := p1 x.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10718
    (t := p2 x) > maxX ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10719
        maxX := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10720
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10721
        t < minX ifTrue:[minX := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10722
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10723
    (t := p3 x) > maxX ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10724
        maxX := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10725
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10726
        t < minX ifTrue:[minX := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10727
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10728
    (t := p4 x) > maxX ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10729
        maxX := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10730
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10731
        t < minX ifTrue:[minX := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10732
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10733
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10734
    maxY := minY := p1 y.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10735
    (t := p2 y) > maxY ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10736
        maxY := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10737
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10738
        t < minY ifTrue:[minY := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10739
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10740
    (t := p3 y) > maxY ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10741
        maxY := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10742
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10743
        t < minY ifTrue:[minY := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10744
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10745
    (t := p4 y) > maxY ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10746
        maxY := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10747
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10748
        t < minY ifTrue:[minY := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10749
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10750
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10751
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10752
    newWidth := (maxX - minX) rounded + 1.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10753
    newHeight := (maxY - minY) rounded + 1.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10754
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10755
    newImage := self species new.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10756
    newImage width:newWidth.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10757
    newImage height:newHeight.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10758
    newBytesPerRow := newImage bytesPerRow.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 10759
    newImage createPixelStore.
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 10760
    newBits := newImage bits.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10761
    newImage photometric:photometric.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10762
    newImage samplesPerPixel:samplesPerPixel.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10763
    newImage bitsPerSample:bitsPerSample.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10764
    newImage colorMap:colorMap copy.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10765
    newImage maskedPixelsAre0:maskedPixelsAre0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10766
    mask notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10767
        newImage mask:(mask rotated:degrees)
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10768
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10769
        self isMask ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10770
            self depth ~~ 1 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10771
                m := ImageMask width:width height:height.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10772
                m bits:(maskBits := ByteArray new:(m bytesPerRow * height)).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10773
                maskBits atAllPut:16rFF.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10774
                newImage mask:(m rotated:degrees)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10775
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10776
        ]
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10777
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10778
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10779
    myDepth := self depth.
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10780
    myDepth == 1 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10781
        blackPixel := 0.
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10782
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10783
        maskedPixelsAre0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10784
            blackPixel := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10785
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10786
            blackPixel := self valueFromColor:Color black.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10787
            blackPixel isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10788
                blackPixel := self valueFromColor:Color white.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10789
                blackPixel isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10790
                    blackPixel := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10791
                ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10792
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10793
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10794
        self isMask ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10795
            blackPixel := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10796
        ].
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10797
    ].
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10798
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10799
    newBits atAllPut:0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10800
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10801
    "/ now, walk over destination pixels,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10802
    "/ fetching from source.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10803
    "/ (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
 10804
    "/  in the destination image ...)
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10805
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10806
    halfW := (width - 1) / 2.0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10807
    halfH := (height - 1) / 2.0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10808
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10809
    bytesPerRow := self bytesPerRow.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10810
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10811
%{
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10812
    int __newHeight = __intVal(newHeight);
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10813
    int __newWidth = __intVal(newWidth);
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10814
    int __height = __intVal(__INST(height));
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10815
    int __width = __intVal(__INST(width));
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10816
    double __minX, __minY, __radians;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10817
    double __halfW, __halfH;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10818
    int __dstX, __dstY;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10819
    int __depth = __intVal(myDepth);
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10820
    unsigned char *__srcBytes, *__dstBytes;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10821
    unsigned char *__dstPtr, *__dstRowPtr, *__dstEndPtr;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10822
    int __nSrcBytes, __nDstBytes;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10823
    int __srcBytesPerRow = __intVal(bytesPerRow);
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10824
    int __dstBytesPerRow = __intVal(newBytesPerRow);
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10825
    int __dstMask, __blackPixel;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10826
    double __sin, __cos;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10827
    double sin(), cos();
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10828
#   define Float_PI 3.14159
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10829
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10830
    bad = true;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10831
    if (1
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10832
     && __isFloat(minX)
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10833
     && __isFloat(minY)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10834
     && __isFloat(radians)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10835
     && __isFloat(halfW)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10836
     && __isFloat(halfH)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10837
     && __isByteArray(newBits)
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
 10838
     && __isByteArrayLike(__INST(bytes))) {
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10839
        __srcBytes = __ByteArrayInstPtr(__INST(bytes))->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10840
        __dstBytes = __ByteArrayInstPtr(newBits)->ba_element;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10841
        __nSrcBytes = __byteArraySize(__INST(bytes));
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10842
        __nDstBytes = __byteArraySize(newBits);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10843
        __blackPixel = __intVal(blackPixel);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10844
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10845
        __radians = __floatVal(radians);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10846
        __radians = -__radians; /* sigh: clock-wise */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10847
        __sin = sin(__radians);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10848
        __cos = cos(__radians);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10849
        __minX = __floatVal(minX);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10850
        __minY = __floatVal(minY);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10851
        __halfW = __floatVal(halfW);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10852
        __halfH = __floatVal(halfH);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10853
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10854
        __dstRowPtr = __dstBytes;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10855
        __dstEndPtr = __dstBytes + __nDstBytes;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10856
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10857
#       define EARLY_OUT
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10858
#       define FAST_ADVANCE 5
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10859
#       define FAST_ADVANCE2
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10860
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10861
        switch (__depth) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10862
            case 8:
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10863
                for (__dstY = 0; __dstY < __newHeight; __dstY++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10864
                    double __pY, __sinPY, __cosPY;
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 10865
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10866
                    int didFetchInRow = 0;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10867
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10868
                    __pY = (double)(__dstY + __minY);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10869
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10870
                    __sinPY = __sin * __pY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10871
                    __cosPY = __cos * __pY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10872
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10873
                    __dstPtr = __dstRowPtr;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10874
                    __dstRowPtr += __dstBytesPerRow;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10875
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10876
                    for (__dstX = 0; __dstX < __newWidth; __dstX++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10877
                        double __pX, __nX;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10878
                        unsigned __pix;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10879
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10880
                        /* translate X in destination (center to 0/0) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10881
                        __pX = (double)(__dstX + __minX);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10882
                        /* rotate X */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10883
                        __nX = (__cos * __pX) - __sinPY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10884
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10885
                        /* translate X in source (origin to 0/0) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10886
                        __nX = __nX + __halfW + 0.5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10887
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10888
                        /* inside ? */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10889
                        if (__nX < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10890
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10891
                            if (didFetchInRow) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10892
                                break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10893
                            }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10894
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10895
#ifdef FAST_ADVANCE
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10896
                            if (__blackPixel == 0) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10897
                                do {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10898
                                    /* try advance by FAST_ADVANCE pixels ... */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10899
                                    __dstX += FAST_ADVANCE; __dstPtr += FAST_ADVANCE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10900
                                    if (__dstX >= __newWidth) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10901
                                        break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10902
                                    }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10903
                                    __pX = (double)(__dstX + __minX);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10904
                                    __nX = (__cos * __pX) - __sinPY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10905
                                    __nX = __nX + __halfW + 0.5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10906
                                } while (__nX < 0);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10907
                                __dstX -= FAST_ADVANCE; __dstPtr -= FAST_ADVANCE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10908
                            }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10909
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10910
                            __pix = __blackPixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10911
                        } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10912
                            int __srcX;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10913
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10914
                            __srcX = (int)__nX;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10915
                            /* inside ? */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10916
                            if (__srcX >= __width) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10917
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10918
                                if (didFetchInRow) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10919
                                    break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10920
                                }
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 10921
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10922
#ifdef FAST_ADVANCE2
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10923
                                if (__blackPixel == 0) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10924
                                    do {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10925
                                        /* try advance by FAST_ADVANCE pixels ... */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10926
                                        __dstX += FAST_ADVANCE; __dstPtr += FAST_ADVANCE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10927
                                        if (__dstX >= __newWidth) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10928
                                            break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10929
                                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10930
                                        __pX = (double)(__dstX + __minX);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10931
                                        __nX = (__cos * __pX) - __sinPY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10932
                                        __nX = __nX + __halfW + 0.5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10933
                                        __srcX = (int)__nX;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10934
                                    } while (__srcX >= __width);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10935
                                    __dstX -= FAST_ADVANCE; __dstPtr -= FAST_ADVANCE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10936
                                }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10937
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10938
                                __pix = __blackPixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10939
                            } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10940
                                double __nY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10941
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10942
                                /* rotate Y */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10943
                                __nY = (__sin * __pX) + __cosPY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10944
                                /* translate Y in source (origin to 0/0) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10945
                                __nY = __nY + __halfH + 0.5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10946
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10947
                                /* inside ? */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10948
                                if (__nY < 0) {
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 10949
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10950
                                    if (didFetchInRow) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10951
                                        break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10952
                                    }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10953
#endif
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10954
#ifdef FAST_ADVANCE2
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10955
                                    if (__blackPixel == 0) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10956
                                        do {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10957
                                            /* try advance by FAST_ADVANCE pixels ... */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10958
                                            __dstX += FAST_ADVANCE; __dstPtr += FAST_ADVANCE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10959
                                            if (__dstX >= __newWidth) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10960
                                                break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10961
                                            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10962
                                            __pX = (double)(__dstX + __minX);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10963
                                            __nY = (__sin * __pX) + __cosPY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10964
                                            __nY = __nY + __halfH + 0.5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10965
                                        } while (__nY < 0);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10966
                                        __dstX -= FAST_ADVANCE; __dstPtr -= FAST_ADVANCE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10967
                                    }
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 10968
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10969
                                    __pix = __blackPixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10970
                                } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10971
                                    int __srcY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10972
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10973
                                    __srcY = (int)__nY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10974
                                    /* inside ? */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10975
                                    if (__srcY >= __height) {
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 10976
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10977
                                        if (didFetchInRow) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10978
                                            break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10979
                                        }
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10980
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10981
#ifdef FAST_ADVANCE
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10982
                                        if (__blackPixel == 0) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10983
                                            do {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10984
                                                /* try advance by FAST_ADVANCE pixels ... */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10985
                                                __dstX += FAST_ADVANCE; __dstPtr += FAST_ADVANCE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10986
                                                if (__dstX >= __newWidth) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10987
                                                    break;
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
                                                __pX = (double)(__dstX + __minX);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10990
                                                __nY = (__sin * __pX) + __cosPY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10991
                                                __nY = __nY + __halfH + 0.5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10992
                                                __srcY = (int)__nY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10993
                                            } while (__srcY >= __height);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10994
                                            __dstX -= FAST_ADVANCE; __dstPtr -= FAST_ADVANCE;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10995
                                        }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10996
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10997
                                        __pix = __blackPixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10998
                                    } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 10999
                                        /* fetch source pixel */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11000
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11001
                                        int idx;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11002
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11003
                                        didFetchInRow = 1;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11004
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11005
                                        idx = __srcY * __srcBytesPerRow + __srcX;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11006
                                        if ((unsigned)idx < __nSrcBytes) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11007
                                            __pix = __srcBytes[idx];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11008
                                        } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11009
                                            __pix = __blackPixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11010
                                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11011
                                    }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11012
                                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11013
                            }
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
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11016
                        if (__pix != 0) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11017
                            *__dstPtr = __pix;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11018
                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11019
                        __dstPtr++;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11020
                    }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11021
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11022
                break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11023
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11024
            case 1:
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11025
                for (__dstY = 0; __dstY < __newHeight; __dstY++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11026
                    double __pY, __sinPY, __cosPY;
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 11027
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11028
                    int didFetchInRow = 0;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11029
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11030
                    __pY = (double)(__dstY + __minY);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11031
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11032
                    __sinPY = __sin * __pY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11033
                    __cosPY = __cos * __pY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11034
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11035
                    __dstPtr = __dstRowPtr;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11036
                    __dstMask = 0x80;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11037
                    __dstRowPtr += __dstBytesPerRow;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11038
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11039
                    for (__dstX = 0; __dstX < __newWidth; __dstX++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11040
                        double __pX, __nX;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11041
                        int __pix;
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
                        /* translate X in destination (center to 0/0) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11044
                        __pX = (double)(__dstX + __minX);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11045
                        /* rotate X */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11046
                        __nX = (__cos * __pX) - __sinPY;
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
                        /* translate X in source (origin to 0/0) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11049
                        __nX = __nX + __halfW + 0.5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11050
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11051
                        /* inside ? */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11052
                        if (__nX < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11053
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11054
                            if (didFetchInRow) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11055
                                break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11056
                            }
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 11057
#endif
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 11058
#ifdef FAST_ADVANCE
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11059
                            if (__blackPixel == 0) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11060
                                do {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11061
                                    /* try advance by 8 pixels ... */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11062
                                    __dstX += 8; __dstPtr ++;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11063
                                    if (__dstX >= __newWidth) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11064
                                        break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11065
                                    }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11066
                                    __pX = (double)(__dstX + __minX);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11067
                                    __nX = (__cos * __pX) - __sinPY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11068
                                    __nX = __nX + __halfW + 0.5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11069
                                } while (__nX < 0);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11070
                                __dstX -= 8; __dstPtr--;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11071
                            }
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11072
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11073
                            __pix = __blackPixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11074
                        } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11075
                            int __srcX;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11076
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11077
                            __srcX = (int)__nX;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11078
                            /* inside ? */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11079
                            if (__srcX >= __width) {
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11080
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11081
                                if (didFetchInRow) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11082
                                    break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11083
                                }
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 11084
#endif
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 11085
#ifdef FAST_ADVANCE2
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11086
                                if (__blackPixel == 0) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11087
                                    do {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11088
                                        /* try advance by 8 pixels ... */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11089
                                        __dstX += 8; __dstPtr++;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11090
                                        if (__dstX >= __newWidth) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11091
                                            break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11092
                                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11093
                                        __pX = (double)(__dstX + __minX);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11094
                                        __nX = (__cos * __pX) - __sinPY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11095
                                        __nX = __nX + __halfW + 0.5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11096
                                        __srcX = (int)__nX;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11097
                                    } while (__srcX >= __width);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11098
                                    __dstX -= 8; __dstPtr--;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11099
                                }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11100
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11101
                                __pix = __blackPixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11102
                            } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11103
                                double __nY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11104
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11105
                                /* rotate Y */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11106
                                __nY = (__sin * __pX) + __cosPY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11107
                                /* translate Y in source (origin to 0/0) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11108
                                __nY = __nY + __halfH + 0.5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11109
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11110
                                /* inside ? */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11111
                                if (__nY < 0) {
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11112
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11113
                                    if (didFetchInRow) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11114
                                        break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11115
                                    }
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 11116
#endif
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 11117
#ifdef FAST_ADVANCE2
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11118
                                    if (__blackPixel == 0) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11119
                                        do {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11120
                                            /* try advance by 8 pixels ... */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11121
                                            __dstX += 8; __dstPtr++;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11122
                                            if (__dstX >= __newWidth) {
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
                                            __pX = (double)(__dstX + __minX);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11126
                                            __nY = (__sin * __pX) + __cosPY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11127
                                            __nY = __nY + __halfH + 0.5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11128
                                        } while (__nY < 0);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11129
                                        __dstX -= 8; __dstPtr--;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11130
                                    }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11131
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11132
                                    __pix = __blackPixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11133
                                } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11134
                                    int __srcY;
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
                                    __srcY = (int)__nY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11137
                                    /* inside ? */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11138
                                    if (__srcY >= __height) {
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 11139
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11140
                                        if (didFetchInRow) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11141
                                            break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11142
                                        }
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 11143
#endif
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 11144
#ifdef FAST_ADVANCE
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11145
                                        if (__blackPixel == 0) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11146
                                            do {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11147
                                                /* try advance by 8 pixels ... */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11148
                                                __dstX += 8; __dstPtr++;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11149
                                                if (__dstX >= __newWidth) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11150
                                                    break;
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
                                                __pX = (double)(__dstX + __minX);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11153
                                                __nY = (__sin * __pX) + __cosPY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11154
                                                __nY = __nY + __halfH + 0.5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11155
                                                __srcY = (int)__nY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11156
                                            } while (__srcY >= __height);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11157
                                            __dstX -= 8; __dstPtr--;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11158
                                        }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11159
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11160
                                        __pix = __blackPixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11161
                                    } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11162
                                        /* fetch source pixel */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11163
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11164
                                        int idx, pV;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11165
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11166
                                        didFetchInRow = 1;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11167
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11168
                                        idx = __srcY * __srcBytesPerRow + (__srcX >> 3);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11169
                                        if ((unsigned)idx < __nSrcBytes) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11170
                                            pV = __srcBytes[idx];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11171
                                            __pix = (pV & (0x80 >> (__srcX & 7))) ? 1 : 0;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11172
                                        } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11173
                                            __pix = __blackPixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11174
                                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11175
                                    }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11176
                                }
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
                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11179
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11180
                        /* store pixel */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11181
                        if (__pix != 0) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11182
                            *__dstPtr |= __dstMask;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11183
                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11184
                        __dstMask >>= 1;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11185
                        if (__dstMask == 0) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11186
                            __dstMask = 0x80;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11187
                            __dstPtr++;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11188
                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11189
                    }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11190
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11191
                break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11192
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11193
            case 24:
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11194
                for (__dstY = 0; __dstY < __newHeight; __dstY++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11195
                    double __pY, __sinPY, __cosPY;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11196
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11197
                    int didFetchInRow = 0;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11198
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11199
                    __pY = (double)(__dstY + __minY);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11200
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11201
                    __sinPY = __sin * __pY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11202
                    __cosPY = __cos * __pY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11203
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11204
                    __dstPtr = __dstRowPtr;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11205
                    __dstRowPtr += __dstBytesPerRow;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11206
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11207
                    for (__dstX = 0; __dstX < __newWidth; __dstX++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11208
                        double __pX, __nX;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11209
                        unsigned __pix;
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
                        /* translate X in destination (center to 0/0) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11212
                        __pX = (double)(__dstX + __minX);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11213
                        /* rotate X */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11214
                        __nX = (__cos * __pX) - __sinPY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11215
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11216
                        /* translate X in source (origin to 0/0) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11217
                        __nX = __nX + __halfW + 0.5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11218
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11219
                        /* inside ? */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11220
                        if (__nX < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11221
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11222
                            if (didFetchInRow) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11223
                                break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11224
                            }
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 11225
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11226
                            __pix = __blackPixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11227
                        } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11228
                            int __srcX;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11229
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11230
                            __srcX = (int)__nX;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11231
                            /* inside ? */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11232
                            if (__srcX >= __width) {
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11233
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11234
                                if (didFetchInRow) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11235
                                    break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11236
                                }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11237
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11238
                                __pix = __blackPixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11239
                            } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11240
                                double __nY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11241
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11242
                                /* rotate Y */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11243
                                __nY = (__sin * __pX) + __cosPY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11244
                                /* translate Y in source (origin to 0/0) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11245
                                __nY = __nY + __halfH + 0.5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11246
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11247
                                /* inside ? */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11248
                                if (__nY < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11249
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11250
                                    if (didFetchInRow) {
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
                                    }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11253
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11254
                                    __pix = __blackPixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11255
                                } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11256
                                    int __srcY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11257
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11258
                                    __srcY = (int)__nY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11259
                                    /* inside ? */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11260
                                    if (__srcY >= __height) {
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11261
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11262
                                        if (didFetchInRow) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11263
                                            break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11264
                                        }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11265
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11266
                                        __pix = __blackPixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11267
                                    } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11268
                                        /* fetch source pixel */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11269
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11270
                                        int idx;
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11271
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11272
                                        didFetchInRow = 1;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11273
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11274
                                        idx = __srcY * __srcBytesPerRow + __srcX + __srcX + __srcX;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11275
                                        if ((unsigned)idx < __nSrcBytes) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11276
                                            __pix = __srcBytes[idx];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11277
                                            __pix = (__pix<<8) | __srcBytes[idx+1];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11278
                                            __pix = (__pix<<8) | __srcBytes[idx+2];
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11279
                                        } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11280
                                            __pix = __blackPixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11281
                                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11282
                                    }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11283
                                }
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
                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11286
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11287
                        /* store pixel */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11288
                        if (__pix != 0) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11289
                            __dstPtr[0] = (__pix >> 16 & 0xFF);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11290
                            __dstPtr[1] = (__pix >> 8) & 0xFF;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11291
                            __dstPtr[2] = __pix & 0xFF;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11292
                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11293
                        __dstPtr += 3;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11294
                    }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11295
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11296
                break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11297
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11298
            default:
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11299
                for (__dstY = 0; __dstY < __newHeight; __dstY++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11300
                    double __pY, __sinPY, __cosPY;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11301
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11302
                    int didFetchInRow = 0;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11303
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11304
                    __pY = (double)(__dstY + __minY);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11305
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11306
                    __sinPY = __sin * __pY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11307
                    __cosPY = __cos * __pY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11308
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11309
                    __dstPtr = __dstRowPtr;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11310
                    __dstMask = 0x80;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11311
                    __dstRowPtr += __dstBytesPerRow;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11312
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11313
                    for (__dstX = 0; __dstX < __newWidth; __dstX++) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11314
                        double __pX, __nX;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11315
                        OBJ __pix;
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 destination (center to 0/0) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11318
                        __pX = (double)(__dstX + __minX);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11319
                        /* rotate X */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11320
                        __nX = (__cos * __pX) - __sinPY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11321
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11322
                        /* translate X in source (origin to 0/0) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11323
                        __nX = __nX + __halfW + 0.5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11324
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11325
                        /* inside ? */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11326
                        if (__nX < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11327
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11328
                            if (didFetchInRow) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11329
                                break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11330
                            }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11331
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11332
                            __pix = blackPixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11333
                        } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11334
                            int __srcX;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11335
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11336
                            __srcX = (int)__nX;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11337
                            /* inside ? */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11338
                            if (__srcX >= __width) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11339
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11340
                                if (didFetchInRow) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11341
                                    break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11342
                                }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11343
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11344
                                __pix = blackPixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11345
                            } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11346
                                double __nY;
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
                                /* rotate Y */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11349
                                __nY = (__sin * __pX) + __cosPY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11350
                                /* translate Y in source (origin to 0/0) */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11351
                                __nY = __nY + __halfH + 0.5;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11352
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11353
                                /* inside ? */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11354
                                if (__nY < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11355
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11356
                                    if (didFetchInRow) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11357
                                        break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11358
                                    }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11359
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11360
                                    __pix = blackPixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11361
                                } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11362
                                    int __srcY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11363
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11364
                                    __srcY = (int)__nY;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11365
                                    /* inside ? */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11366
                                    if (__srcY >= __height) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11367
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11368
                                        if (didFetchInRow) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11369
                                            break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11370
                                        }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11371
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11372
                                        __pix = blackPixel;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11373
                                    } else {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11374
                                        /* fetch source pixel */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11375
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11376
                                        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
 11377
#ifdef EARLY_OUT
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11378
                                        didFetchInRow = 1;
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11379
#endif
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11380
                                        __pix = (*valAt.ilc_func)(self,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11381
                                                              @symbol(pixelAtX:y:),
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11382
                                                              nil, &valAt,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11383
                                                              __MKSMALLINT(__srcX),
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11384
                                                              __MKSMALLINT(__srcY));
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
                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11389
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11390
                        /* store pixel */
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11391
                        {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11392
                            static struct inlineCache atPutVal = _ILC3;
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
                            if (__pix != __MKSMALLINT(0)) {
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11395
                                (*atPutVal.ilc_func)(newImage,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11396
                                                      @symbol(pixelAtX:y:put:),
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11397
                                                      nil, &atPutVal,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11398
                                                      __MKSMALLINT(__dstX),
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11399
                                                      __MKSMALLINT(__dstY),
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11400
                                                      __pix
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11401
                                                     );
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11402
                            }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11403
                        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11404
                    }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11405
                }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11406
                break;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11407
        }
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11408
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11409
        bad = false;
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11410
    }
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11411
%}.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11412
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11413
    bad ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11414
        "/ should not happen
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11415
        self primitiveFailed
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11416
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11417
"/        sinRot := radians negated sin.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11418
"/        cosRot := radians negated cos.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11419
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11420
"/        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
 11421
"/            pY := (dstY + minY).
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11422
"/            sinPY := (sinRot * pY).
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11423
"/            cosPY := (cosRot * pY).
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11424
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11425
"/            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
 11426
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11427
"/                "/ translate center to origin
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11428
"/                pX := (dstX + minX).
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11429
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11430
"/                nX := (cosRot * pX) - sinPY.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11431
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11432
"/                "/ translate in source
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11433
"/                srcX := nX + halfW.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11434
"/                srcX := srcX rounded.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11435
"/                "/ inside ?
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11436
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11437
"/                (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
 11438
"/                    nY := (sinRot * pX) + cosPY.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11439
"/                    srcY := nY + halfH.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11440
"/                    srcY := srcY rounded.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11441
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11442
"/                    "/ inside ?
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11443
"/                    (srcY >= 0 and:[srcY < height]) ifTrue:[
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 11444
"/                        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
 11445
"/                    ] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11446
"/                        pix := blackPixel.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11447
"/                    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11448
"/                ] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11449
"/                    pix := blackPixel.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11450
"/                ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11451
"/                pix ~~ blackPixel ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11452
"/                    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
 11453
"/                ]
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11454
"/            ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11455
"/        ].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11456
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11457
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11458
    ^ newImage
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11459
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11460
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11461
     |i|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11462
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 11463
     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
 11464
     i inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11465
     (i rotated:45) inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11466
     (i rotated:90) inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11467
     (i rotated:91) inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11468
     (i rotated:95) inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11469
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11470
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11471
     |i|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11472
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 11473
     i := Smalltalk imageFromFileNamed:'bitmaps/gifImages/garfield.gif' inPackage:'stx:goodies'.
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 11474
     i := Depth24Image fromImage:i.
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 11475
     (i rotated:200) inspect
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11476
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11477
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11478
     |i|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11479
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 11480
     i := Smalltalk imageFromFileNamed:'bitmaps/gifImages/garfield.gif' inPackage:'stx:goodies'.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11481
     Transcript showCR:(
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11482
        Time millisecondsToRun:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11483
           i rotated:45.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11484
        ]
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11485
     ).
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11486
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11487
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11488
     |v i rI rot|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11489
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 11490
     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
 11491
     v := View new extent:(i width max:100)@(i height max:100).
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11492
     v openAndWait.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11493
     rot := 0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11494
     [true] whileTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11495
        rI := i rotated:rot.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11496
        rI := rI onDevice:v device.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11497
        v clear.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11498
        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
 11499
        rot := rot + 5.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11500
        rI close.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11501
     ]
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11502
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11503
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11504
     |v i rI rot|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11505
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 11506
     i := Smalltalk imageFromFileNamed:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies'.
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 11507
     v := View new extent:400@400.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11508
     v openAndWait.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11509
     rot := 0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11510
     [true] whileTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11511
        rI := i rotated:rot.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11512
        rI := rI onDevice:v device.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11513
        v clear.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11514
        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
 11515
        rot := rot + 5.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11516
        rI close.
4952
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11517
     ]
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11518
    "
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11519
    "
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11520
     |v i rI rot|
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11521
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11522
     i := Form width:200 height:100 onDevice:Screen current.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11523
     i clear.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11524
     i displayLineFrom:(0@0) to:(199@0).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11525
     i displayLineFrom:(199@0) to:(199@99).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11526
     i displayLineFrom:(199@99) to:(0@99).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11527
     i displayLineFrom:(0@99) to:(0@0).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11528
     i displayLineFrom:(0@0) to:(199@100).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11529
     i displayLineFrom:(199@0) to:(0@100).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11530
     i := Image fromForm:i.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11531
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11532
     v := View new extent:400@400.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11533
     v openAndWait.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11534
     rot := 0.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11535
     [true] whileTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11536
        rI := i rotated:rot.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11537
        rI := rI onDevice:v device.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11538
        v clear.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11539
        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
 11540
        rot := rot + 5.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11541
        rI close.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11542
        Delay waitForSeconds:0.1.
4952
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11543
     ]
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11544
    "
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11545
    "
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11546
     |v i rI rot|
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11547
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11548
     i := Form width:200 height:100 onDevice:Screen current.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11549
     i clear.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11550
     i displayLineFrom:(0@0) to:(199@0).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11551
     i displayLineFrom:(199@0) to:(199@99).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11552
     i displayLineFrom:(199@99) to:(0@99).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11553
     i displayLineFrom:(0@99) to:(0@0).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11554
     i displayLineFrom:(0@0) to:(199@100).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11555
     i displayLineFrom:(199@0) to:(0@100).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11556
     i := Image fromForm:i.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11557
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11558
     v := View new extent:400@400.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11559
     v openAndWait.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11560
     rot := 0.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11561
     [true] whileTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11562
        rI := i rotated:rot.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11563
        rI := rI onDevice:v device.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11564
        v clear.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11565
        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
 11566
        rot := rot + 30.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11567
        rI close.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11568
        Delay waitForSeconds:0.3.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11569
     ]
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
    "Modified: 22.4.1997 / 17:36:37 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 11573
!
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 11574
54
29a6b2f8e042 *** empty log message ***
claus
parents: 46
diff changeset
 11575
lightened
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 11576
    "return a new image which is slightly brighter than the receiver.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 11577
     The receiver must be a palette image (currently).
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11578
     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
 11579
     CAVEAT: Need an argument, which specifies by how much it should be lighter."
54
29a6b2f8e042 *** empty log message ***
claus
parents: 46
diff changeset
 11580
5655
37bd5c7eb765 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 5643
diff changeset
 11581
    ^ self copyWithColorMapProcessing:[:clr | clr lightened]
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11582
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11583
    "
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11584
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11585
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') lightened inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11586
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') darkened inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11587
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') darkened darkened inspect
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11588
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11589
5655
37bd5c7eb765 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 5643
diff changeset
 11590
    "Modified: / 24-11-2010 / 11:17:55 / cg"
54
29a6b2f8e042 *** empty log message ***
claus
parents: 46
diff changeset
 11591
!
29a6b2f8e042 *** empty log message ***
claus
parents: 46
diff changeset
 11592
134
claus
parents: 132
diff changeset
 11593
magnifiedBy:scale
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 11594
    "return a new image magnified by scalePoint, aPoint.
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
 11595
     If non-integral magnify is asked for, pass the work on to 'hardMagnifyBy:'
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
 11596
     while simple (integral) magnifications are handled here."
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11597
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 11598
    |scalePoint mX mY
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11599
     magX      "{ Class: SmallInteger }"   "new version of stc can find this out itself..."
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11600
     magY      "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11601
     srcOffset "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11602
     dstOffset "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11603
     w         "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11604
     h         "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11605
     first
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 11606
     newWidth newHeight newImage newBits newMask
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 11607
     bitsPerPixel newBytesPerRow oldBytesPerRow
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 11608
     bytes|
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11609
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 11610
    scalePoint := scale asPoint.
2772
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
 11611
    mX := scalePoint x.
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
 11612
    mY := scalePoint y.
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11613
    ((mX <= 0) or:[mY <= 0]) ifTrue:[^ nil].
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11614
    ((mX = 1) and:[mY = 1]) ifTrue:[^ self].
48194c26a46c Initial revision
claus
parents:
diff changeset
 11615
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11616
    ((mX isMemberOf:SmallInteger) and:[mY isMemberOf:SmallInteger]) ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11617
        ^ self hardMagnifiedBy:scalePoint
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 11618
    ].
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 11619
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 11620
    bytes := self bits.
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
 11621
    bitsPerPixel := self depth.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11622
    oldBytesPerRow := ((width * bitsPerPixel) + 7) // 8.
48194c26a46c Initial revision
claus
parents:
diff changeset
 11623
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11624
    w := width.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11625
    h := height.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11626
    magX := mX.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11627
    magY := mY.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11628
2772
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
 11629
    newWidth := w * magX.
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
 11630
    newHeight := h * magY.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11631
    newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8.
48194c26a46c Initial revision
claus
parents:
diff changeset
 11632
    newBits := ByteArray uninitializedNew:(newBytesPerRow * newHeight).
48194c26a46c Initial revision
claus
parents:
diff changeset
 11633
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 11634
    mask notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11635
        newMask := (mask magnifiedBy:scalePoint)
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 11636
    ].
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 11637
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11638
    newImage := self species new.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11639
    newImage
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11640
        width:newWidth
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11641
        height:newHeight
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11642
        photometric:photometric
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11643
        samplesPerPixel:samplesPerPixel
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11644
        bitsPerSample:bitsPerSample
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11645
        colorMap:colorMap copy
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11646
        bits:newBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11647
        mask:newMask.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11648
48194c26a46c Initial revision
claus
parents:
diff changeset
 11649
    mX = 1 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11650
        "expand rows only"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11651
        srcOffset := 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11652
        dstOffset := 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11653
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11654
        1 to:h do:[:row |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11655
            1 to:magY do:[:i |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11656
                newBits replaceFrom:dstOffset
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11657
                        to:(dstOffset + oldBytesPerRow - 1)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11658
                        with:bytes
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11659
                        startingAt:srcOffset.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11660
                dstOffset := dstOffset + newBytesPerRow
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11661
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11662
            srcOffset := srcOffset + oldBytesPerRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11663
        ].
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11664
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11665
        "expand cols"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11666
        (mX > 1) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11667
            dstOffset := 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11668
            srcOffset := 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11669
            1 to:h do:[:row |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11670
                self magnifyRowFrom:bytes
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11671
                     offset:srcOffset
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11672
                     into:newBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11673
                     offset:dstOffset
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11674
                     factor:mX.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11675
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11676
                first := dstOffset.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11677
                dstOffset := dstOffset + newBytesPerRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11678
                " and copy for row expansion "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11679
                2 to:magY do:[:i |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11680
                    newBits replaceFrom:dstOffset
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11681
                            to:(dstOffset + newBytesPerRow - 1)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11682
                            with:newBits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11683
                            startingAt:first.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11684
                    dstOffset := dstOffset + newBytesPerRow
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11685
                ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11686
                srcOffset := srcOffset + oldBytesPerRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11687
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11688
        ]
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11689
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
 11690
    ^ newImage
48194c26a46c Initial revision
claus
parents:
diff changeset
 11691
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11692
    "
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11693
     ((Image fromFile:'goodies/bitmaps/gifImages/claus.gif') magnifiedBy:1@2)
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11694
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11695
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11696
    "Modified: 24.4.1997 / 18:32:04 / cg"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
 11697
!
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
 11698
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11699
magnifiedPreservingRatioTo:anExtent
154
claus
parents: 153
diff changeset
 11700
    "return a new image magnified to fit into anExtent,
7242
bf3a75233d55 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7230
diff changeset
 11701
     preserving the receiver's width/height ratio.
154
claus
parents: 153
diff changeset
 11702
     (i.e. not distorting the image).
claus
parents: 153
diff changeset
 11703
     See also #magnifiedTo: and #magnifiedBy:"
claus
parents: 153
diff changeset
 11704
claus
parents: 153
diff changeset
 11705
    |rX rY|
claus
parents: 153
diff changeset
 11706
claus
parents: 153
diff changeset
 11707
    rX := anExtent x / self width.
claus
parents: 153
diff changeset
 11708
    rY := anExtent y / self height.
claus
parents: 153
diff changeset
 11709
    ^ self magnifiedBy:(rX min:rY)
claus
parents: 153
diff changeset
 11710
claus
parents: 153
diff changeset
 11711
    "
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11712
     ((Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') magnifiedPreservingRatioTo:100@100)
154
claus
parents: 153
diff changeset
 11713
claus
parents: 153
diff changeset
 11714
    in contrast to:
claus
parents: 153
diff changeset
 11715
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11716
     ((Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') magnifiedTo:100@100)
1630
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 11717
    "
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 11718
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 11719
    "Modified: 22.4.1997 / 12:33:46 / cg"
154
claus
parents: 153
diff changeset
 11720
!
claus
parents: 153
diff changeset
 11721
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11722
magnifiedTo:anExtent
154
claus
parents: 153
diff changeset
 11723
    "return a new image magnified to have the size specified by extent.
claus
parents: 153
diff changeset
 11724
     This may distort the image if the arguments ratio is not the images ratio.
claus
parents: 153
diff changeset
 11725
     See also #magnifiedPreservingRatioTo: and #magnifiedBy:"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 11726
134
claus
parents: 132
diff changeset
 11727
    ^ self magnifiedBy:(anExtent / self extent)
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 11728
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 11729
    "
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 11730
     ((Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') magnifiedTo:100@100)
154
claus
parents: 153
diff changeset
 11731
claus
parents: 153
diff changeset
 11732
    in contrast to:
claus
parents: 153
diff changeset
 11733
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 11734
     ((Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') magnifiedPreservingRatioTo:100@100)
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 11735
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 11736
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 11737
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11738
mixed:amount with:aColor
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11739
    "return a new image which is blended with some color;
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11740
     amount determines how much of the blending color is applied (0..)
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11741
     where 0 means: blending color pure.
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11742
     The receiver must be a palette image (currently).
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11743
     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
 11744
     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
 11745
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11746
     ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11747
        copyWithColorMapProcessing:[:clr | clr mixed:amount with:aColor]
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11748
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11749
    "
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11750
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11751
     ((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
 11752
     ((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
 11753
     ((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
 11754
     ((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
 11755
     ((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
 11756
     ((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
 11757
     ((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
 11758
    "
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11759
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11760
    "Modified: 24.4.1997 / 18:31:23 / cg"
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11761
!
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11762
1762
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11763
negative
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11764
    "return a new image which is a negative of the receiver.
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11765
     The receiver must be a palette image (currently)."
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11766
1763
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 11767
    |newImage|
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 11768
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 11769
    colorMap isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11770
        photometric == #blackIs0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11771
            newImage := self copy.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11772
            newImage photometric:#whiteIs0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11773
            ^ newImage
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11774
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11775
        photometric == #whiteIs0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11776
            newImage := self copy.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11777
            newImage photometric:#blackIs0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11778
            ^ newImage
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11779
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11780
        ^ nil
1763
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 11781
    ].
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 11782
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11783
     ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11784
        copyWithColorMapProcessing:[:clr |
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 11785
                Color
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 11786
                    redByte:(255 - clr redByte)
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 11787
                    greenByte:(255 - clr greenByte)
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 11788
                    blueByte:(255 - clr blueByte)
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 11789
            ]
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11790
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11791
    "
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11792
     (Image fromFile:'goodies/bitmaps/gifImages/claus.gif') inspect
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11793
     (Image fromFile:'goodies/bitmaps/gifImages/claus.gif') negative inspect
1762
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11794
    "
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11795
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 11796
    "Created: / 20-06-1997 / 13:13:41 / cg"
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 11797
    "Modified: / 31-01-2017 / 14:43:19 / stefan"
1762
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11798
!
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11799
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11800
rotated:degrees
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11801
    "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
 11802
     degrees clockwise.
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 11803
     Notice that the resulting image has a different extent.
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11804
     If rotation is heavily used, the workHorse methods
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11805
     (#easyRotateBitsInto:angle: and #hardRotateBitsInto:angle) may
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11806
     be redefined in concrete image subclasses."
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11807
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 11808
    |nW nH newImage d|
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11809
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11810
    d := degrees.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11811
    [d < 0] whileTrue:[d := d + 360].
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11812
    d >= 360 ifTrue:[d := d \\ 360].
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11813
    d := d truncated.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11814
    d = 0 ifTrue:[^ self].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11815
    ((d ~= 90) and:[(d ~= 270) and:[d ~= 180]]) ifTrue:[
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 11816
        ^ self hardRotated:d
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11817
    ].
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11818
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11819
    d = 180 ifTrue:[
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 11820
        nW := width.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 11821
        nH := height.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11822
    ] ifFalse:[
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 11823
        nW := height.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 11824
        nH := width.
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11825
    ].
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11826
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11827
    newImage := self species new.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11828
    newImage width:nW.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11829
    newImage height:nH.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 11830
    newImage createPixelStore.
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11831
    newImage photometric:photometric.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11832
    newImage samplesPerPixel:samplesPerPixel.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11833
    newImage bitsPerSample:bitsPerSample.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11834
    newImage colorMap:colorMap copy.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11835
    mask notNil ifTrue:[
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 11836
        newImage mask:(mask rotated:degrees)
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11837
    ].
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11838
7534
0b7e23635791 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7529
diff changeset
 11839
    self easyRotateBitsInto:newImage angle:d.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11840
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11841
    ^ newImage
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 11842
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11843
    "
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11844
     |i|
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11845
7529
5f77a718b7bd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7523
diff changeset
 11846
     i := Image fromFile:'../../goodies/bitmaps/gifImages/claus.gif'.
7534
0b7e23635791 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7529
diff changeset
 11847
     i inspect.
0b7e23635791 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7529
diff changeset
 11848
     (i rotated:45) inspect.
0b7e23635791 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7529
diff changeset
 11849
     (i rotated:90) inspect.
0b7e23635791 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7529
diff changeset
 11850
     (i rotated:180) inspect.
0b7e23635791 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7529
diff changeset
 11851
     (i rotated:270) inspect.
0b7e23635791 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7529
diff changeset
 11852
    "
0b7e23635791 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7529
diff changeset
 11853
    "
0b7e23635791 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7529
diff changeset
 11854
     |i|
0b7e23635791 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7529
diff changeset
 11855
0b7e23635791 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7529
diff changeset
 11856
     i := Image fromFile:'../../goodies/bitmaps/gifImages/claus.gif'.
7529
5f77a718b7bd #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7523
diff changeset
 11857
     i := Depth24Image fromImage:i.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11858
     i inspect.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11859
     (i rotated:45) inspect.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11860
     (i rotated:90) inspect.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11861
     (i rotated:180) inspect.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11862
     (i rotated:270) inspect.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11863
    "
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11864
    "
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11865
     |i|
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11866
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11867
     i := Image fromFile:'goodies/bitmaps/xpmBitmaps/misc_icons/BOOK.xpm'.
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11868
     i inspect.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11869
     (i rotated:90) inspect.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11870
     (i rotated:180) inspect.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11871
     (i rotated:270) inspect.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11872
    "
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11873
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11874
    "Modified: 24.4.1997 / 18:33:42 / cg"
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11875
!
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11876
6624
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11877
slightlyDarkened
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11878
    "return a new image which is slightly darker than the receiver.
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11879
     The receiver must be a palette image (currently).
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11880
     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
 11881
     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
 11882
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11883
    ^ self copyWithColorMapProcessing:[:clr | clr slightlyDarkened]
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11884
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11885
    "
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11886
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') inspect
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11887
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') lightened inspect
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11888
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') darkened inspect
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11889
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') darkened darkened inspect
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11890
    "
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11891
!
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11892
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11893
slightlyLightened
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11894
    "return a new image which is slightly brighter than the receiver.
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11895
     The receiver must be a palette image (currently).
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11896
     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
 11897
     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
 11898
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11899
    ^ self copyWithColorMapProcessing:[:clr | clr slightlyLightened]
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11900
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11901
    "
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11902
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') inspect
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11903
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') lightened inspect
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11904
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') darkened inspect
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11905
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') darkened darkened inspect
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11906
    "
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11907
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11908
    "Modified: / 24-11-2010 / 11:17:55 / cg"
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11909
!
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11910
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11911
threeDProjected:fraction1 and:fraction2
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11912
    "return a 3D-projected version"
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11913
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 11914
    |dx1 dx2 newImage newBits
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 11915
     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
 11916
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11917
    newImage := self species new.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11918
    newImage width:width.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11919
    newImage height:height.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11920
    newImage createPixelStore.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11921
    newBits := newImage bits.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11922
    newImage photometric:photometric.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11923
    newImage samplesPerPixel:samplesPerPixel.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11924
    newImage bitsPerSample:bitsPerSample.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11925
    newImage colorMap:colorMap copy.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11926
    newImage maskedPixelsAre0:maskedPixelsAre0.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11927
    mask notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11928
        newImage mask:(mask threeDProjected:fraction1 and:fraction2)
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11929
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11930
        self isMask ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11931
            self depth ~~ 1 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11932
                m := ImageMask width:width height:height.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11933
                m bits:(maskBits := ByteArray new:(m bytesPerRow * height)).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11934
                maskBits atAllPut:16rFF.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11935
                newImage mask:(m threeDProjected:fraction1 and:fraction2)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11936
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11937
        ]
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11938
    ].
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11939
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11940
    myDepth := self depth.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11941
    myDepth == 1 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11942
        blackPixel := 0.
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11943
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11944
        maskedPixelsAre0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11945
            blackPixel := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11946
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11947
            blackPixel := self valueFromColor:Color black.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11948
            blackPixel isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11949
                blackPixel := self valueFromColor:Color white.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11950
                blackPixel isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11951
                    blackPixel := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11952
                ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11953
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11954
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11955
        self isMask ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11956
            blackPixel := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11957
        ].
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11958
    ].
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11959
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11960
    newBits atAllPut:0.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11961
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11962
    "/ now, walk over destination pixels,
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11963
    "/ fetching from source.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11964
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11965
    halfH := (height - 1) / 2.0.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11966
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11967
    "/  --------------------------------------------------------------
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11968
    "/  |**************                                              |
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11969
    "/  |              ************                                  | dx1
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11970
    "/  |                          *************                     |
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11971
    "/  |                                       **********           |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11972
    "/  |fl                          fy                   ***********|
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11973
    "/  |                                                            | fr
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11974
    "/  |                                                            | Mr  (!!= Ml)      |
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11975
    "/  |Ml                          my                              | fr               | dm (=Mr-Ml)
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11976
    "/  |                                                     *******|                  |
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11977
    "/  |                            fy              *********       |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11978
    "/  |fl                                 *********                |
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11979
    "/  |                          *********                         | dx2
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11980
    "/  |                 *********                                  |
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11981
    "/  |        *********                                           |
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11982
    "/  |********                                                    |
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11983
    "/  --------------------------------------------------------------
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11984
    dx1 := height * fraction1.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11985
    dx2 := height * fraction2.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11986
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11987
    fr := (height - dx1 - dx2) / 2.0.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11988
    fl := (height) / 2.0.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11989
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11990
    ml := height / 2.0.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11991
    mr := dx1+fr.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11992
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11993
    dm := mr-ml.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11994
    df := fr-fl.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11995
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11996
    0 to:width-1 do:[:srcX |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11997
        fractX := srcX / width.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11998
        my := ml + (dm * fractX).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 11999
        fy := fl + (df * fractX).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12000
        o1 := dx1 * fractX.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12001
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12002
        0 to:height-1 do:[:srcY |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12003
            srcY < halfH ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12004
                dstY := o1 + (fy * (srcY / halfH)).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12005
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12006
                dstY := my + (fy * ((srcY-halfH) / halfH)).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12007
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12008
            pix := self pixelAtX:srcX y:srcY.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12009
            dstY < 0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12010
                ifTrue:[dstY := 0]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12011
                ifFalse:[ dstY >= height ifTrue:[dstY := height-1]].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12012
            newImage pixelAtX:srcX y:dstY truncated put:pix.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12013
        ].
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12014
    ].
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12015
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12016
    ^ newImage
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
    "
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12019
     |i|
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12020
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12021
     i := Smalltalk imageFromFileNamed:'bitmaps/gifImages/garfield.gif' inPackage:'stx:goodies'.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12022
     i := Depth24Image fromImage:i.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12023
     (i threeDProjected:0.1 and:0.3) inspect
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12024
     (i threeDProjected:0.1 and:0.1) inspect
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12025
    "
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 12026
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 12027
    "Modified: / 31-01-2017 / 15:04:22 / stefan"
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12028
!
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 12029
3905
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12030
withColorResolutionReducedBy:numBits
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12031
    "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
 12032
     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
 12033
     If anything fails, return nil."
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12034
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12035
    |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
 12036
     newColors newColorArray newImage extMask extBits newPixelValue|
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12037
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12038
    numBits > 7 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12039
        ^ nil
3905
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12040
    ].
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12041
    mask := (16rFF bitShift:numBits) bitAnd:16rFF.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12042
    extMask := (1 bitShift:numBits).
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12043
    extBits := extMask - 1.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12044
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12045
    anyChange := false.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12046
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12047
    newColors := Set new.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12048
    newColorArray := OrderedCollection new.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12049
    map := Array new:256.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12050
    revMap := OrderedCollection new.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12051
4317
a24172a52a76 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4296
diff changeset
 12052
    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
 12053
    newImage photometric:photometric.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12054
    newImage colorMap:(self colorMap copy).
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12055
    newImage bits:(self bits copy).
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12056
    newImage mask:(self mask copy).
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12057
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12058
    xMax := width - 1.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12059
    yMax := height - 1.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12060
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12061
    newPixelValue :=
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12062
        [:image :pixelValue |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12063
            |r g b nR nG nB|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12064
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12065
            r := image redBitsOf:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12066
            g := image greenBitsOf:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12067
            b := image blueBitsOf:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12068
            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
 12069
            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
 12070
            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
 12071
            image valueFromRedBits:nR greenBits:nG blueBits:nB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12072
        ].
3905
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12073
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12074
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 12075
    photometric ~~ #palette ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12076
        "/ direct manipulation of the pixels
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12077
        0 to:yMax do:[:y |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12078
            0 to:xMax do:[:x |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12079
                pix := self pixelAtX:x y:y.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12080
                n_pix := newPixelValue value:self value:pix.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12081
                n_pix ~= pix ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12082
                    newImage pixelAtX:x y:y put:n_pix.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12083
                    anyChange := true.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12084
                ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12085
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12086
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12087
        anyChange ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12088
            ^ nil
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12089
        ].
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 12090
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12091
        "/ manipulate the colormap
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12092
        0 to:yMax do:[:y |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12093
            0 to:xMax do:[:x |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12094
                pix := self pixelAtX:x y:y.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12095
                (n_pix := map at:pix+1) isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12096
                    clr := self colorAtX:x y:y.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12097
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12098
                    r := clr redByte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12099
                    g := clr greenByte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12100
                    b := clr blueByte.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12101
                    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
 12102
                    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
 12103
                    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
 12104
                    n_clr := Color redByte:nR greenByte:nG blueByte:nB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12105
                    (newColors includes:n_clr) ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12106
                        newColors add:n_clr.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12107
                        newColorArray add:n_clr.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12108
                        revMap add:pix.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12109
                        map at:pix+1 put:(n_pix := revMap size - 1).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12110
                    ] ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12111
                        "/ mhmh - multiple pixels mapped to the same color
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12112
                        n_pix := (newColorArray indexOf:n_clr) - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12113
                        map at:pix+1 put:n_pix.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12114
                    ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12115
                ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12116
                newImage pixelAtX:x y:y put:n_pix.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12117
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12118
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12119
        revMap size == self colorMap size ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12120
            revMap = (0 to:revMap size-1) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12121
                ^ nil
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12122
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12123
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12124
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12125
        newImage colorMap:(MappedPalette withColors:newColorArray).
3905
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12126
    ].
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12127
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12128
    ^ newImage
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 12129
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 12130
    "Modified: / 30-01-2017 / 20:15:02 / stefan"
3905
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12131
!
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 12132
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12133
withPixelFunctionApplied:pixelFunctionBlock
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12134
    "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
 12135
     on the pixel colors.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12136
     Notice: this method is very slow - either apply pixel values
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12137
     (#withPixelFunctionAppliedToPixels:) or redefine this method in
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12138
     a concrete subclass.
3860
571f1cd259f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3855
diff changeset
 12139
     (read `Beyond photography, by Gerard J. Holzmann;
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12140
           ISBM 0-13-074410-7)
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12141
     See blurred / oilPointed as examples ...)"
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12142
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12143
    |w  "{Class: SmallInteger }"
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12144
     h  "{Class: SmallInteger }"
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 12145
     newImage "newBits newBytesPerRow"|
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12146
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12147
    newImage := self species new.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12148
    newImage depth:self depth.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12149
    newImage width:width.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12150
    newImage height:height.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12151
"/    newBytesPerRow := ((width * self depth) + 7) // 8.
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12152
"/    newBits := ByteArray uninitializedNew:(newBytesPerRow * height).
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12153
    newImage createPixelStore. "/ bits:newBits.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12154
    newImage photometric:photometric.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12155
    newImage samplesPerPixel:samplesPerPixel.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12156
    newImage bitsPerSample:bitsPerSample.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12157
    newImage colorMap:colorMap copy.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12158
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12159
    w := width - 1.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12160
    h := height - 1.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12161
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12162
    0 to:h do:[:y |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12163
        0 to:w do:[:x |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12164
            newImage colorAtX:x y:y put:(pixelFunctionBlock
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12165
                                                value:self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12166
                                                value:(self colorAtX:x y:y)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12167
                                                value:x
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12168
                                                value:y)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12169
        ]
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12170
    ].
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12171
    ^ newImage
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12172
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12173
    "black out everything except for some rectangle:
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12174
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 12175
     |i black|
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12176
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12177
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12178
     i inspect.
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 12179
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 12180
     black := Color black.
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 12181
     (i withPixelFunctionApplied:[:oldImage :oldColor :x :y |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12182
                        ((x between:100 and:200)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12183
                        and:[y between:100 and:200]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12184
                            oldColor
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12185
                        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12186
                            black.
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
                     ]) inspect.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12189
    "
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12190
    "brighten a frame:
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12191
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12192
     |i black w h|
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12193
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12194
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12195
     i inspect.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12196
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12197
     w := i width.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12198
     h := i height.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12199
     (i withPixelFunctionApplied:[:oldImage :oldColor :x :y |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12200
                        ((x between:0 and:10)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12201
                        or:[(y between:0 and:10)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12202
                        or:[(x between:w-10 and:w)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12203
                        or:[y between:h-10 and:h]]]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12204
                            oldColor lightened nearestIn:i colorMap
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12205
                        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12206
                            oldColor.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12207
                        ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12208
                     ]) inspect.
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12209
    "
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12210
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12211
    "Modified: 24.4.1997 / 18:36:59 / cg"
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12212
!
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12213
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12214
withPixelFunctionAppliedToPixels:pixelFunctionBlock
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12215
    "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
 12216
     on the pixel values.
4296
240f73781089 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4226
diff changeset
 12217
     (read `Beyond photography, by Gerard J. Holzmann;
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12218
           ISBM 0-13-074410-7)
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12219
     See blurred / oilPointed as examples ...)"
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12220
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12221
    ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12222
        withPixelFunctionAppliedToPixels:pixelFunctionBlock
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12223
        in:(0@0 corner:width@height)
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12224
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12225
    "oil painting effect:
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12226
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12227
     |i w h|
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12228
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12229
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12230
     i inspect.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12231
     w := i width - 1.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12232
     h := i height - 1.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12233
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12234
                        |b p max xMin xMax yMin yMax|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12235
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12236
                        b := Bag identityNew:10.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12237
                        xMin := x-3 max:0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12238
                        xMax := x+3 min:w.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12239
                        yMin := y-3 max:0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12240
                        yMax := y+3 min:h.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12241
                        xMin to:xMax do:[:tx|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12242
                          yMin to:yMax do:[:ty|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12243
                            b add:(oldImage pixelAtX:tx y:ty)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12244
                          ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12245
                        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12246
                        max := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12247
                        b contents keysAndValuesDo:[:pixel :n |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12248
                            n > max ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12249
                                p := pixel.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12250
                                max := n
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12251
                            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12252
                        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12253
                        p
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12254
                     ]) inspect.
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12255
    "
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12256
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12257
    "fisheye effect:
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12258
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12259
     |i w h w2 h2 R white|
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12260
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12261
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12262
     i inspect.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12263
     w := i width - 1.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12264
     h := i height - 1.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12265
     w2 := w // 2.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12266
     h2 := h // 2.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12267
     R := w2.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12268
     white := i valueFromColor:Color white.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12269
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12270
                        |p r a nR nP nX nY|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12271
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12272
                        p := (x-w2)@(y-h2).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12273
                        r := p r.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12274
                        a := p theta.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12275
                        nR := r * r / R.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12276
                        nP := Point r:nR theta:a.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12277
                        nX := ((nP x+w2) rounded max:0) min:w.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12278
                        nY := ((nP y+h2) rounded max:0) min:h.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12279
                        (nX > w or:[nX < 0]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12280
                            white
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12281
                        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12282
                            (nY > h or:[nY < 0]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12283
                                white
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12284
                            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12285
                                oldImage pixelAtX:nX y:nY
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12286
                            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12287
                        ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12288
                     ]) inspect.
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12289
    "
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12290
    "fisheye effect:
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12291
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12292
     |i w h w2 h2 R white|
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12293
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12294
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12295
     i inspect.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12296
     w := i width - 1.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12297
     h := i height - 1.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12298
     w2 := w // 2.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12299
     h2 := h // 2.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12300
     R := w2.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12301
     white := i valueFromColor:Color white.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12302
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12303
                        |p r a nR nP nX nY|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12304
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12305
                        p := (x-w2)@(y-h2).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12306
                        r := p r.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12307
                        a := p theta.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12308
                        nR := r * r / R.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12309
                        nP := Point r:nR theta:a.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12310
                        nX := (nP x+w2) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12311
                        nY := (nP y+h2) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12312
                        (nX > w or:[nX < 0]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12313
                            white
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12314
                        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12315
                            (nY > h or:[nY < 0]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12316
                                white
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12317
                            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12318
                                oldImage pixelAtX:nX y:nY
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12319
                            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12320
                        ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12321
                     ]) inspect.
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12322
    "
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12323
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12324
    "Created: 24.4.1997 / 18:37:17 / cg"
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12325
    "Modified: 24.4.1997 / 18:40:02 / cg"
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12326
!
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
withPixelFunctionAppliedToPixels:pixelFunctionBlock in:aRectangle
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12329
    "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
 12330
     on the pixel values.
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 12331
     (read `Beyond photography, by Gerard J. Holzmann;
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12332
           ISBM 0-13-074410-7)
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12333
     See blurred / oilPointed as examples ...)"
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12334
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 12335
    |newImage "newBits newBytesPerRow"|
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12336
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12337
    newImage := self species new.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12338
    newImage depth:self depth.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12339
    newImage width:width.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12340
    newImage height:height.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12341
"/    newBytesPerRow := ((width * self depth) + 7) // 8.
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12342
"/    newBits := ByteArray uninitializedNew:(newBytesPerRow * height).
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12343
    newImage createPixelStore. "/ bits:newBits
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12344
    newImage photometric:photometric.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12345
    newImage samplesPerPixel:samplesPerPixel.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12346
    newImage bitsPerSample:bitsPerSample.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12347
    newImage colorMap:colorMap copy.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12348
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12349
    self applyPixelValuesTo:pixelFunctionBlock in:aRectangle into:newImage.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12350
    ^ newImage
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12351
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12352
    "oil painting effect:
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12353
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12354
     |i w h|
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12355
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12356
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12357
     i inspect.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12358
     w := i width - 1.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12359
     h := i height - 1.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12360
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12361
                        |b p max xMin xMax yMin yMax|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12362
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12363
                        b := Bag identityNew:10.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12364
                        xMin := x-3 max:0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12365
                        xMax := x+3 min:w.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12366
                        yMin := y-3 max:0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12367
                        yMax := y+3 min:h.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12368
                        xMin to:xMax do:[:tx|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12369
                          yMin to:yMax do:[:ty|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12370
                            b add:(oldImage pixelAtX:tx y:ty)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12371
                          ]
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
                        max := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12374
                        b contents keysAndValuesDo:[:pixel :n |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12375
                            n > max ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12376
                                p := pixel.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12377
                                max := n
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12378
                            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12379
                        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12380
                        p
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12381
                     ]) inspect.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12382
    "
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12383
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12384
    "fisheye effect:
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12385
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 12386
     |i w h w2 h2 R white|
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12387
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12388
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12389
     i inspect.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12390
     w := i width - 1.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12391
     h := i height - 1.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12392
     w2 := w // 2.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12393
     h2 := h // 2.
1510
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12394
     R := w2.
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 12395
     white := i valueFromColor:Color white.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12396
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12397
                        |p r a nR nP nX nY|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12398
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12399
                        p := (x-w2)@(y-h2).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12400
                        r := p r.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12401
                        a := p theta.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12402
                        nR := r * r / R.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12403
                        nP := Point r:nR theta:a.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12404
                        nX := ((nP x+w2) rounded max:0) min:w.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12405
                        nY := ((nP y+h2) rounded max:0) min:h.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12406
                        (nX > w or:[nX < 0]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12407
                            white
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12408
                        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12409
                            (nY > h or:[nY < 0]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12410
                                white
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12411
                            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12412
                                oldImage pixelAtX:nX y:nY
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12413
                            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12414
                        ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12415
                     ]) inspect.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12416
    "
1510
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12417
    "fisheye effect:
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12418
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12419
     |i w h w2 h2 R white|
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12420
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12421
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
1510
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12422
     i inspect.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12423
     w := i width - 1.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12424
     h := i height - 1.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12425
     w2 := w // 2.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12426
     h2 := h // 2.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12427
     R := w2.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12428
     white := i valueFromColor:Color white.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12429
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12430
                        |p r a nR nP nX nY|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12431
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12432
                        p := (x-w2)@(y-h2).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12433
                        r := p r.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12434
                        a := p theta.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12435
                        nR := r * r / R.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12436
                        nP := Point r:nR theta:a.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12437
                        nX := (nP x+w2) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12438
                        nY := (nP y+h2) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12439
                        (nX > w or:[nX < 0]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12440
                            white
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12441
                        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12442
                            (nY > h or:[nY < 0]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12443
                                white
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12444
                            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12445
                                oldImage pixelAtX:nX y:nY
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12446
                            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12447
                        ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12448
                     ]) inspect.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12449
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12450
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12451
    "Created: 24.4.1997 / 18:37:17 / cg"
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12452
    "Modified: 24.4.1997 / 18:40:02 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12453
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12454
3870
8245e3f37feb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
 12455
!Image methodsFor:'initialization'!
8245e3f37feb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
 12456
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12457
createPixelStore
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12458
    |bytesPerRow|
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12459
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12460
    bytesPerRow := self bytesPerRow.
5643
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
 12461
    self bits:(ByteArray new:(bytesPerRow * self height)).
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
 12462
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
 12463
    "Modified: / 02-11-2010 / 20:57:11 / cg"
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12464
!
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12465
3871
a7867fb8d880 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3870
diff changeset
 12466
initialize
3870
8245e3f37feb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
 12467
    self photometric:(self class defaultPhotometric)
8245e3f37feb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
 12468
! !
8245e3f37feb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
 12469
5037
2e515c9ee849 changed #valueFromColor:
Claus Gittinger <cg@exept.de>
parents: 4998
diff changeset
 12470
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12471
!Image methodsFor:'instance release'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12472
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12473
close
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12474
    "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
 12475
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12476
    deviceForm notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12477
        deviceForm destroy.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12478
        deviceForm := nil.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12479
    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12480
    monoDeviceForm notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12481
        monoDeviceForm destroy.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12482
        monoDeviceForm := nil.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12483
    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12484
    fullColorDeviceForm notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12485
        fullColorDeviceForm destroy.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12486
        fullColorDeviceForm := nil.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12487
    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12488
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12489
    device := nil.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12490
    mask notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12491
        mask close.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12492
    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12493
    Lobby unregister:self.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12494
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12495
    "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
 12496
    "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
 12497
!
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12498
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12499
release
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12500
    "release device resources"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12501
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12502
    device := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12503
    deviceForm := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12504
    monoDeviceForm := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12505
    fullColorDeviceForm := nil.
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
 12506
    mask notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12507
        mask release.
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
 12508
    ].
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
 12509
    Lobby unregister:self.
1746
72a583dd30bd must not forget super release
Claus Gittinger <cg@exept.de>
parents: 1739
diff changeset
 12510
    super release.
72a583dd30bd must not forget super release
Claus Gittinger <cg@exept.de>
parents: 1739
diff changeset
 12511
72a583dd30bd must not forget super release
Claus Gittinger <cg@exept.de>
parents: 1739
diff changeset
 12512
    "Modified: 11.6.1997 / 13:20:04 / cg"
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 12513
!
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 12514
4226
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12515
releaseFromDevice
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12516
    "release device resources"
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12517
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12518
    device := nil.
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12519
    deviceForm := nil.
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12520
    monoDeviceForm := nil.
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12521
    fullColorDeviceForm := nil.
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12522
7573
656c59bc93ad #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7565
diff changeset
 12523
4226
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12524
    "Modified: 16.1.1997 / 19:33:01 / cg"
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12525
!
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12526
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12527
restored
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12528
    "flush device specifics after a snapin or binary restore"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12529
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12530
    self release
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12531
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12532
2227
7aa9e2a8d321 added #edit - to open an image editor.
Claus Gittinger <cg@exept.de>
parents: 2212
diff changeset
 12533
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12534
!Image methodsFor:'obsolete'!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12535
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12536
applyPixelValuesTo:pixelFunctionBlock into:newImage in:aRectangle
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12537
    "helper for withPixelFunctionAppliedToValues:
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12538
     enumerate pixelValues and evaluate the block for each.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12539
     To be redefined by subclasses for better performance."
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12540
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12541
    ^ self applyPixelValuesTo:pixelFunctionBlock in:aRectangle into:newImage
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12542
!
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12543
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12544
magnifyBy:scale
5216
f7ec910cfce1 Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 5200
diff changeset
 12545
    <resource: #obsolete>
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12546
    "obsolete: has been renamed to magnifiedBy: for ST-80 compatibility
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12547
     and name consistency ..."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12548
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12549
    self obsoleteMethodWarning.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12550
    ^ self magnifiedBy:scale
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12551
! !
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12552
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12553
!Image methodsFor:'pixel copying'!
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
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
 12556
    "replace a rectangular area by pixels from another image.
7552
6d862b1829d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7551
diff changeset
 12557
     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
 12558
     colorMap - otherwise, an error will be reported.
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12559
     Any mask is copied from the source.
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 12560
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12561
     WARNING:
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 12562
       This implementation is a very slow fallback general algorithm
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 12563
       (the loop over the source pixels is very slow).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12564
       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
 12565
       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
 12566
       with the same depth & palette.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12567
       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
 12568
       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
 12569
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12570
    |dX dY|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12571
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12572
    dX := srcX-dstX.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12573
    dY := srcY-dstY.
1248
6afcdec18986 commentary
Claus Gittinger <cg@exept.de>
parents: 1230
diff changeset
 12574
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12575
    ((photometric == anImage photometric)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12576
     and:[self bitsPerPixel == anImage bitsPerPixel
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12577
     and:[colorMap = anImage colorMap]]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12578
        "/ can loop over values
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12579
        anImage valuesFromX:srcX  y:srcY
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12580
                        toX:srcX+w-1 y:srcY+h-1
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12581
                         do:[:x :y :pixelValue |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12582
            self pixelAtX:x-dX y:y-dY put:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12583
        ]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12584
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12585
        "/ must loop over colors - horribly slow
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12586
        anImage colorsFromX:srcX  y:srcY
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12587
                        toX:srcX+w-1 y:srcY+h-1
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12588
                         do:[:x :y :clr |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12589
            self colorAtX:x-dX y:y-dY put:clr.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12590
        ]
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12591
    ].
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12592
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12593
    (mask isNil and:[anImage mask notNil]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12594
        "/ I have no mask; copied image has
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12595
        self createMask.
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12596
    ].
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12597
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12598
    mask notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12599
        anImage mask notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12600
            "/ both have a mask
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12601
            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
 12602
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12603
            "/ I have a mask - copied image has not
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12604
            mask fillRectangleX:dstX y:dstY width:w height:h withValue:1
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12605
        ]
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12606
"/    ] ifFalse:[
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12607
"/        anImage mask notNil ifTrue:[
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12608
"/            "/ I have no mask; copied image has (already handled)
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12609
"/        ] ifFalse:[
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12610
"/            "/ none has a mask - nothing to do.
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12611
"/        ]
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12612
    ].
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12613
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12614
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12615
     |i1 i8 i4|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12616
7552
6d862b1829d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7551
diff changeset
 12617
     i8 := Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif'.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12618
     i8 inspect.
7552
6d862b1829d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7551
diff changeset
 12619
     i1 := Image fromFile:'../../libtool/bitmaps/SBrowser.xbm'.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12620
     i1 inspect.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12621
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12622
     i4 := Depth4Image fromImage:i8.
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 12623
     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
 12624
     i4 inspect.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12625
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12626
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12627
    "Created: 20.9.1995 / 10:14:01 / claus"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12628
    "Modified: 20.9.1995 / 10:25:31 / claus"
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 12629
    "Modified: 21.6.1997 / 13:15:31 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12630
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12631
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12632
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
 12633
    "replace a rectangular area by pixels from another image.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12634
     The sources colors must be present in the destinations
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12635
     colorMap - otherwise, an error will be reported.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12636
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12637
     WARNING:
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12638
       This implementation is a very slow fallback general algorithm
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12639
       (the loop over the source pixels is very slow).
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12640
       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
 12641
       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
 12642
       with the same depth & palette.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12643
       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
 12644
       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
 12645
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12646
    maskedCopy ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12647
        self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12648
            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
 12649
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12650
        self
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12651
            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
 12652
    ].
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12653
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12654
    "
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12655
     |i1 i8 i4|
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12656
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12657
     i8 := Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif'.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12658
     i8 inspect.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12659
     i1 := Image fromFile:'../../goodies/bitmaps/xbmBitmaps/TicTacToe.xbm'.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12660
     i1 inspect.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12661
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12662
     i4 := Depth4Image fromImage:i8.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12663
     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
 12664
     i4 inspect.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12665
    "
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12666
!
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12667
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12668
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
 12669
    "replace a rectangular area by pixels from another image.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12670
     The sources colors must be present in the destinations
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12671
     colorMap - otherwise, an error will be reported.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12672
     Only unmasked pixels are copied from the source.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12673
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12674
     WARNING:
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12675
       This implementation is a very slow fallback general algorithm
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12676
       (the loop over the source pixels is very slow).
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12677
       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
 12678
       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
 12679
       with the same depth & palette.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12680
       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
 12681
       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
 12682
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12683
    |dX dY|
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12684
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12685
    dX := srcX-dstX.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12686
    dY := srcY-dstY.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12687
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12688
    ((photometric == anImage photometric)
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12689
     and:[self bitsPerPixel == anImage bitsPerPixel
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12690
     and:[colorMap = anImage colorMap]]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12691
        "/ can loop over values
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12692
        anImage valuesFromX:srcX  y:srcY
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12693
                        toX:srcX+w-1 y:srcY+h-1
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12694
                         do:[:x :y :pixelValue |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12695
            (anImage maskAtX:x y:y) ~~ 0 ifTrue:[
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
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12698
        ]
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12699
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12700
        "/ must loop over colors - horribly slow
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12701
        anImage colorsFromX:srcX  y:srcY
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12702
                        toX:srcX+w-1 y:srcY+h-1
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12703
                         do:[:x :y :clr |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12704
            (anImage maskAtX:x y:y) ~~ 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12705
                self colorAtX:x-dX y:y-dY put:clr.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12706
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12707
        ]
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12708
    ].
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12709
!
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12710
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12711
subImageIn:aRectangle
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12712
    "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
 12713
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12714
    ^ self class fromSubImage:self in:aRectangle
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12715
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12716
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12717
     |i|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12718
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 12719
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12720
     i inspect.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12721
     (i subImageIn:(300@160 corner:340@200)) inspect
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12722
    "
7551
a58984867d2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7537
diff changeset
 12723
    "
a58984867d2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7537
diff changeset
 12724
     |i|
a58984867d2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7537
diff changeset
 12725
a58984867d2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7537
diff changeset
 12726
     i := Image fromFile:'/Volumes/tmp/fillimage.ok.png'.
a58984867d2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7537
diff changeset
 12727
     i inspect.
a58984867d2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7537
diff changeset
 12728
     (i subImageIn:(0@0 corner:i width@i height)) inspect
a58984867d2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7537
diff changeset
 12729
    "
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12730
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12731
    "Created: 20.9.1995 / 01:24:20 / claus"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12732
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12733
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12734
!Image methodsFor:'pixel functions'!
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12735
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12736
computeBitsFromPixelFunction
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12737
    "compute the bits from the pixelfunction"
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12738
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 12739
    |bpr|
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12740
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12741
    bpr := self bytesPerRow.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12742
    bytes := ByteArray new:(bpr * height).
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12743
    0 to:height-1 do:[:y |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12744
        0 to:width-1 do:[:x |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12745
            self pixelAtX:x y:y put:(pixelFunction value:x value:y).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12746
        ]
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12747
    ].
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 12748
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 12749
    "Modified: / 31-01-2017 / 14:39:26 / stefan"
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12750
!
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12751
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12752
pixelFunction
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12753
    ^ pixelFunction
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12754
!
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12755
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12756
pixelFunction:aTwoArgFunction
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12757
    "set the pixel function. This is used to define a functional image,
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12758
     where pixel values are computed via a function instead of coming
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12759
     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
 12760
     a pixel function).
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12761
     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
 12762
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12763
    pixelFunction := aTwoArgFunction.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12764
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12765
    "
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12766
     |i|
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12767
     i := Depth1Image extent:256@256.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12768
     i pixelFunction:[:x :y | ((x // 16) bitXor:(y // 16)) odd asInteger].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12769
     i inspect.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12770
    "
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12771
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12772
    "
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12773
     |i|
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12774
     i := Depth8Image extent:256@256.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12775
     i photometric:#blackIs0.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12776
     i pixelFunction:[:x :y | x  ].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12777
     i inspect.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12778
    "
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12779
!
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12780
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12781
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
 12782
    "set the pixel function and a viewport.
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12783
     This is used to define a functional image,
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12784
     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
 12785
     from a bits array.
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12786
     The pixelFunction will map (x E xInterval) x (y E yInterval) -> pixel"
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12787
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12788
    |sX sY tX tY|
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12789
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12790
    "/ intervals are typically 0..1
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12791
    sX := (xInterval stop - xInterval start) asFloat / width.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12792
    sY := (yInterval stop - yInterval start) asFloat / height.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12793
    tX := xInterval start.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12794
    tY := yInterval start.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12795
7373
61933c223183 added metaData instVar (for free use by image reader)
Claus Gittinger <cg@exept.de>
parents: 7363
diff changeset
 12796
    pixelFunction :=
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12797
        [:x :y |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12798
            aTwoArgFunction value:(x * sX + tX) value:(y * sY + tY)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12799
        ]
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12800
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12801
    "
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12802
     |i|
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12803
     i := Depth8Image extent:256@256.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12804
     i photometric:#blackIs0.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12805
     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
 12806
     i inspect.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12807
    "
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12808
! !
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12809
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12810
!Image methodsFor:'printing & storing'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12811
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12812
storeOn:aStream
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12813
    "append a printed representation of the receiver to aStream,
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12814
     from which a copy of it can be reconstructed."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12815
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12816
    |colors usedValues colorMapArray needBPS needSemi|
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12817
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12818
    needSemi := false.
7373
61933c223183 added metaData instVar (for free use by image reader)
Claus Gittinger <cg@exept.de>
parents: 7363
diff changeset
 12819
    aStream nextPutAll:('(%1 width:%2 height:%3'
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12820
                            bindWith:self class name
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12821
                            with:width
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12822
                            with:height).
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12823
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12824
    "/ 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
 12825
    "/ no need for the photometric, if it's the default anyway
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12826
    photometric ~= self class defaultPhotometric ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12827
        (colorMap isNil or:[photometric ~~ #palette]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12828
            aStream nextPutAll:' photometric:('. photometric storeOn:aStream. aStream nextPut:$).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12829
        ].
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12830
    ].
7349
361f96216120 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7292
diff changeset
 12831
    aStream nextPut:$).
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12832
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12833
    "/ no need to store bitPerSample/samplesPerPixel in all situations
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12834
    needBPS := true.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12835
7373
61933c223183 added metaData instVar (for free use by image reader)
Claus Gittinger <cg@exept.de>
parents: 7363
diff changeset
 12836
    self depth == 1
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12837
        ifTrue:[ needBPS := false ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12838
        ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12839
            ((photometric == #palette)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12840
                and:[ (bitsPerSample size == 1)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12841
                and:[ ((bitsPerSample at:1) == self depth)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12842
                and:[ samplesPerPixel == 1 ]]])
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12843
            ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12844
                needBPS := false.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12845
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12846
        ].
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12847
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12848
    needBPS ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12849
        needSemi ifTrue:[aStream nextPutAll:';'].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12850
        aStream nextPutAll:' bitsPerSample:('. bitsPerSample storeOn:aStream. aStream nextPutAll:')'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12851
        samplesPerPixel ~= bitsPerSample size ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12852
            aStream nextPutAll:'; samplesPerPixel:('. samplesPerPixel storeOn:aStream. aStream nextPutAll:')'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12853
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12854
        needSemi := true.
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12855
    ].
5533
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 12856
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 12857
    "/ assert that all bits are there...
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 12858
    "/ self assert:(self bits size) >= (self bytesPerRow * height).
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 12859
    "/ 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
 12860
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12861
    needSemi ifTrue:[aStream nextPutAll:';'].
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12862
    aStream nextPutAll:' bits:(ByteArray fromPackedString:'. self bits asPackedString storeOn:aStream.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12863
    aStream nextPutAll:')'.
2068
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
 12864
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
 12865
    colorMap notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12866
        self depth <= 8 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12867
            "/ cut off unused colors ...
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12868
            usedValues := self usedValues.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12869
            colors := colorMap copyFrom:1 to:((usedValues max+1) min:colorMap size).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12870
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12871
            colorMapArray := OrderedCollection new.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12872
            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
 12873
            aStream cr; spaces:12; nextPutAll:'colorMapFromArray:'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12874
            colorMapArray asByteArray storeOn:aStream.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12875
        ] ifFalse:[
7834
329ce8391689 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7824
diff changeset
 12876
            false ifTrue:[
329ce8391689 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7824
diff changeset
 12877
                aStream cr; spaces:12; nextPutAll:'colorMap:('.
329ce8391689 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7824
diff changeset
 12878
                colorMap storeOn:aStream.
329ce8391689 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7824
diff changeset
 12879
                aStream nextPutAll:')'
329ce8391689 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7824
diff changeset
 12880
            ]
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12881
        ]
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12882
    ].
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
 12883
    mask notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12884
        aStream cr; spaces:12; nextPutAll:'mask:('.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12885
        mask storeOn:aStream.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12886
        aStream nextPutAll:')'.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12887
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12888
    aStream nextPutAll:'; yourself'
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
 12889
7834
329ce8391689 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 7824
diff changeset
 12890
    "Modified: / 03-02-2017 / 16:56:29 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 12891
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
 12892
48194c26a46c Initial revision
claus
parents:
diff changeset
 12893
!Image methodsFor:'private'!
48194c26a46c Initial revision
claus
parents:
diff changeset
 12894
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12895
bestSupportedImageFormatFor:aDevice
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12896
    "scan through the image formats as supported by aDevice,
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12897
     and return the best to use when the receiver is to be represented
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12898
     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
 12899
     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
 12900
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
 12901
    |bestDeviceDepth
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
 12902
     bestDeviceBitsPerPixel "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12903
     "maxDepth"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12904
     bestInfo maxInfo
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
 12905
     myDepth                "{ Class: SmallInteger }"
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
 12906
     maxBitsPerPixel        "{ Class: SmallInteger }"|
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12907
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12908
    myDepth := self bitsPerPixel.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12909
    maxBitsPerPixel := 0.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12910
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12911
    aDevice supportedImageFormats do:[:entry |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12912
        |deviceImageDepth        "{ Class: SmallInteger }"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12913
         deviceImageBitsPerPixel "{ Class: SmallInteger }" |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12914
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12915
        deviceImageDepth := entry at:#depth.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12916
        deviceImageBitsPerPixel := entry at:#bitsPerPixel.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12917
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12918
        "/ 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
 12919
        "/ devices depth.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12920
        "/ (actually, many devices can handle other pixMap formats,
7659
01fe20eef85d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7640
diff changeset
 12921
        "/ 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
 12922
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12923
        ((deviceImageDepth == 1) or:[deviceImageDepth == aDevice depth]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12924
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12925
            deviceImageBitsPerPixel > maxBitsPerPixel ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12926
                maxInfo := entry.
2050
d1f21c75b5eb when asking a device for its supported pixmap formats,
Claus Gittinger <cg@exept.de>
parents: 2043
diff changeset
 12927
    "/            maxBitsPerPixel := deviceImageBitsPerPixel.
d1f21c75b5eb when asking a device for its supported pixmap formats,
Claus Gittinger <cg@exept.de>
parents: 2043
diff changeset
 12928
    "/            maxDepth := deviceImageDepth.
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12929
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12930
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12931
            deviceImageDepth >= myDepth ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12932
                deviceImageDepth == myDepth ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12933
                    "/ take the better one ...
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12934
                    (bestDeviceDepth isNil
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12935
                     or:[(bestDeviceBitsPerPixel ~~ bestDeviceDepth)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12936
                        and:[deviceImageDepth == deviceImageBitsPerPixel]]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12937
                        bestInfo := entry.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12938
                        bestDeviceDepth := deviceImageDepth.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12939
                        bestDeviceBitsPerPixel := deviceImageBitsPerPixel.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12940
                    ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12941
                ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12942
                    "/ take the next-larger depth
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12943
                    (bestDeviceDepth isNil
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12944
                     or:[deviceImageBitsPerPixel < bestDeviceBitsPerPixel]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12945
                        bestInfo := entry.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12946
                        bestDeviceDepth := deviceImageDepth.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12947
                        bestDeviceBitsPerPixel := deviceImageBitsPerPixel.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12948
                    ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12949
                ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12950
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12951
        ].
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12952
    ].
851
c9511f8945ce fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents: 841
diff changeset
 12953
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12954
    bestDeviceDepth isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12955
        maxBitsPerPixel == 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12956
            "/
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12957
            "/ oops - nothing appropriate
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12958
            "/
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12959
            maxInfo notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12960
                ^ maxInfo
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12961
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12962
            bestDeviceDepth := bestDeviceBitsPerPixel := aDevice depth.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12963
            bestInfo := IdentityDictionary new.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12964
            bestInfo at:#depth put:bestDeviceDepth.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12965
            bestInfo at:#bitsPerPixel put:bestDeviceBitsPerPixel.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12966
            bestInfo at:#padding put:32.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12967
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12968
            bestInfo := maxInfo.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12969
        ]
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12970
    ].
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
 12971
    ^ bestInfo
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
 12972
2050
d1f21c75b5eb when asking a device for its supported pixmap formats,
Claus Gittinger <cg@exept.de>
parents: 2043
diff changeset
 12973
    "Modified: / 7.2.1998 / 11:23:24 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12974
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12975
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12976
colormapFromImage:anImage
7242
bf3a75233d55 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7230
diff changeset
 12977
    "setup the receiver's colormap from another image.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12978
     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
 12979
     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
 12980
     for fromImage:/fromSubImake:"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12981
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 12982
    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
 12983
!
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 12984
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 12985
colormapFromImage:anImage photometric:photometricOrNil
7242
bf3a75233d55 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7230
diff changeset
 12986
    "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
 12987
     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
 12988
     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
 12989
     for fromImage:/fromSubImake:"
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 12990
2447
5b3d802d602b allow Image fromImage with rgb source-image and palette receiver
Claus Gittinger <cg@exept.de>
parents: 2415
diff changeset
 12991
    |usedColors|
5b3d802d602b allow Image fromImage with rgb source-image and palette receiver
Claus Gittinger <cg@exept.de>
parents: 2415
diff changeset
 12992
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12993
    samplesPerPixel == 3 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12994
        photometric := photometricOrNil ? #rgb
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12995
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12996
        photometricOrNil isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12997
            photometric := anImage photometric.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12998
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 12999
            photometric := photometricOrNil.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13000
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13001
        photometric == #palette ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13002
            self setColorMap:(anImage colorMap copy).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13003
            "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13004
             must generate/compress the colormap, if source image has higher depth
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13005
             than myself.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13006
            "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13007
            (colorMap isNil
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13008
            or:[anImage bitsPerPixel > self bitsPerPixel]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13009
                "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13010
                 get used colors are extracted into our colorMap
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13011
                 (the at-put below will set the pixelValue according the
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13012
                 new colorIndex
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13013
                "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13014
                self setColorMap:(anImage usedColors asArray).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13015
                colorMap size > (1 bitShift:self bitsPerPixel) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13016
                    'Image [warning]: possibly too many colors in image' errorPrintCR
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13017
                ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13018
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13019
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13020
            (photometric == #blackIs0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13021
            or:[ photometric == #whiteIs0 ]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13022
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13023
                usedColors := anImage usedColors asArray.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13024
                usedColors size > (1 bitShift:self bitsPerPixel) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13025
                    'Image [warning]: possibly too many colors in image' errorPrintCR.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13026
                    usedColors := usedColors copyTo:(1 bitShift:self bitsPerPixel).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13027
                ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13028
                self setColorMap:usedColors.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13029
                photometric := #palette
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13030
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13031
        ]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13032
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13033
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13034
    "Created: 20.9.1995 / 00:58:42 / claus"
1175
5595569cfbd3 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 1170
diff changeset
 13035
    "Modified: 10.1.1997 / 17:52:21 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13036
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13037
7637
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 13038
fromDeviceForm:aForm maskForm:aMaskFormOrNil
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 13039
    device := aForm device.
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 13040
    self assert:device notNil.
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 13041
    photometric := aForm photometric.
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 13042
    deviceForm := aForm.
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 13043
    width := aForm width.
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 13044
    height := aForm height.
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 13045
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 13046
    aMaskFormOrNil notNil ifTrue:[
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 13047
        mask := Image fromDeviceForm:aMaskFormOrNil maskForm:nil.
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 13048
    ].
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 13049
!
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 13050
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13051
greyByteMapForRange:range
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13052
    "return a collection to map from pixelValues to greyLevels
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13053
     in the range 0..range.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13054
     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
 13055
     The values are rounded towards the nearest pixel."
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13056
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
 13057
    |d clr val greyMap r
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
 13058
     n "{ Class: SmallInteger }"|
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 13059
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 13060
    r := range.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 13061
    r == 256 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13062
        r := 255
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13063
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13064
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13065
    photometric == #palette ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13066
        n := colorMap size.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13067
        greyMap := ByteArray new:n.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13068
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13069
        1 to:n do:[:i |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13070
            (clr := colorMap at:i) isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13071
                "/ an unused color
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13072
                val := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13073
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13074
                val := (r * clr brightness) rounded
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
            greyMap at:i put:val
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13077
        ].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13078
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13079
        d := self bitsPerPixel.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13080
        n := 1 bitShift:d.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13081
        n >= 4096 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13082
            self error:'size not supported - too large'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13083
            ^ nil
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13084
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13085
        greyMap := ByteArray new:n.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13086
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13087
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13088
        photometric == #rgb ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13089
            1 to:n do:[:i |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13090
                greyMap at:i put:(r * (self colorFromValue:i-1) brightness) rounded
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13091
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13092
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13093
            1 to:n do:[:i |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13094
                greyMap at:i put:(r / (n-1) * (i-1)) rounded
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13095
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13096
            photometric == #blackIs0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13097
                "/ we are done
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13098
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13099
                photometric == #whiteIs0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13100
                    greyMap reverse
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13101
                ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13102
                    self error:'invalid format'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13103
                    ^ nil
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13104
                ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13105
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13106
        ].
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13107
    ].
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 13108
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13109
    ^ greyMap
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13110
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13111
    "
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 13112
     Depth8Image new greyByteMapForRange:256
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 13113
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 13114
     Depth8Image new greyByteMapForRange:64
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 13115
     Depth4Image new greyByteMapForRange:64
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 13116
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 13117
     Depth4Image new greyByteMapForRange:1
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13118
    "
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13119
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13120
    "Created: 8.6.1996 / 08:34:14 / cg"
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
 13121
    "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
 13122
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13123
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13124
greyMapForRange:range
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13125
    "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
 13126
     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
 13127
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
 13128
    |d r clr val
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 13129
     n "{Class: SmallInteger }"
1927
d1bbdf03e5a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1919
diff changeset
 13130
     n2 "{Class: SmallInteger }"
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 13131
     greyArray|
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13132
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13133
    d := self bitsPerPixel.
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13134
    n := 1 bitShift:d.
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13135
    n >= 4096 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13136
        self error:'size not supported - too large'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13137
        ^ nil
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13138
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13139
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 13140
    greyArray := Array new:n.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13141
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13142
    photometric == #palette ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13143
        n2 := colorMap size.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13144
        1 to:n2 do:[:i |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13145
            (clr := colorMap at:i) isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13146
                "/ an unused color
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13147
                val := 0.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13148
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13149
                val := range * clr brightness
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13150
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13151
            greyArray at:i put:val
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13152
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13153
        n2 < n ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13154
            greyArray from:n2+1 to:n put:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13155
        ]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13156
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13157
        photometric == #rgb ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13158
            1 to:n do:[:i |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13159
                greyArray at:i put:(range * (self colorFromValue:(i-1)) brightness)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13160
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13161
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13162
            r := range asFloat.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13163
            1 to:n do:[:i |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13164
                greyArray at:i put:(r / (n-1) * (i-1))
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13165
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13166
            photometric == #blackIs0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13167
                "/ we are done
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13168
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13169
                photometric == #whiteIs0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13170
                    greyArray reverse
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13171
                ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13172
                    self error:'invalid format'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13173
                    ^ nil
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13174
                ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13175
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13176
        ]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13177
    ].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 13178
    ^ greyArray
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13179
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13180
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13181
     Depth8Image new greyMapForRange:64
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13182
     Depth4Image new greyMapForRange:64
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13183
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 13184
     Depth16Image new greyMapForRange:1
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13185
     Depth4Image new greyMapForRange:1
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 13186
     Depth2Image new greyMapForRange:1
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 13187
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 13188
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
 13189
    "Modified: 1.3.1997 / 15:48:49 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13190
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13191
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13192
magnifyRowFrom:srcBytes offset:srcStart
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13193
          into:dstBytes offset:dstStart factor:mX
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13194
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13195
    "magnify a single pixel row - can only magnify by integer factors,
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13196
     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
 13197
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13198
    ^ self subclassResponsibility
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13199
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13200
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13201
makeDeviceGrayPixmapOn:aDevice depth:depth fromArray:bits
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13202
    "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
 13203
     pixels interpreted as greyValues, 0 is black,
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13204
     create a device form for it"
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13205
7755
75f5eba88e77 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7689
diff changeset
 13206
    |f gcId|
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13207
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 13208
    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
 13209
    f isNil ifTrue:[^ nil].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13210
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13211
    f bits:bits.
7755
75f5eba88e77 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7689
diff changeset
 13212
    gcId := f initGC.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13213
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13214
    (aDevice blackpixel ~~ 0) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13215
        "/ have to invert bits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13216
        f function:#copyInverted
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13217
    ].
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13218
    aDevice
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13219
        drawBits:bits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13220
        depth:depth
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13221
        padding:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13222
        width:width height:height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13223
        x:0 y:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13224
        into:(f id)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13225
        x:0 y:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13226
        width:width height:height
7755
75f5eba88e77 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7689
diff changeset
 13227
        with:gcId.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13228
    ^ f
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13229
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13230
    "Created: 10.6.1996 / 20:10:31 / cg"
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13231
!
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13232
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13233
makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13234
    "given the bits of a monochrome bitmap, 8-bit padded and
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13235
     0-bits as black, create a device form for it"
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13236
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
 13237
"/    monoBits invert.
4769
0cabcf1481a0 Use Form class>>#width:height:fromArray:onDevice: instead of obsolete
Stefan Vogel <sv@exept.de>
parents: 4762
diff changeset
 13238
    ^ (Form width:width height:height fromArray:monoBits onDevice:aDevice)
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13239
        colorMap:(Array with:Color black with:Color white).
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13240
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13241
    "Created: 10.6.1996 / 20:18:09 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
 13242
    "Modified: 17.4.1997 / 01:07:38 / cg"
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13243
!
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13244
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13245
makeDevicePixmapOn:aDevice depth:depth fromArray:bits
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13246
    "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
 13247
     pixels interpreted as in the devices colormap,
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13248
     create a device form for it"
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13249
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13250
    |f|
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13251
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 13252
    f := Form width:width height:height depth:depth onDevice:aDevice.
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13253
    f isNil ifTrue:[^ nil].
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13254
    f bits:bits.
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13255
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13256
    aDevice
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13257
        drawBits:bits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13258
        depth:depth
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13259
        padding:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13260
        width:width height:height
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13261
        x:0 y:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13262
        into:(f id)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13263
        x:0 y:0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13264
        width:width height:height
7755
75f5eba88e77 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7689
diff changeset
 13265
        with:(f initGC).
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13266
    ^ f
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13267
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13268
    "Created: 10.6.1996 / 17:56:08 / cg"
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13269
    "Modified: 10.6.1996 / 20:11:27 / cg"
5237
e28aca881988 repairPhotometric
Claus Gittinger <cg@exept.de>
parents: 5235
diff changeset
 13270
!
e28aca881988 repairPhotometric
Claus Gittinger <cg@exept.de>
parents: 5235
diff changeset
 13271
e28aca881988 repairPhotometric
Claus Gittinger <cg@exept.de>
parents: 5235
diff changeset
 13272
repairPhotometric
e28aca881988 repairPhotometric
Claus Gittinger <cg@exept.de>
parents: 5235
diff changeset
 13273
    "/ kludge: repair a 'should not happen' situation...
e28aca881988 repairPhotometric
Claus Gittinger <cg@exept.de>
parents: 5235
diff changeset
 13274
    photometric isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13275
        (self depth == 24 and:[ bitsPerSample size == 3 ]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13276
            photometric := #rgb
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13277
        ].
5237
e28aca881988 repairPhotometric
Claus Gittinger <cg@exept.de>
parents: 5235
diff changeset
 13278
    ].
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
 13279
! !
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 13280
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13281
!Image methodsFor:'queries'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13282
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13283
alphaBitsOf:pixel
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13284
    "if the receiver is an rgb-image:
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13285
     return the alpha component of a pixelValue as integer 0..maxAlphaValue.
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13286
     MaxAlphaValue is of course the largest integer representable by the number
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13287
     of alpha bits i.e. (1 bitShift:bitsAlpha)-1.
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13288
     This has to be redefined by subclasses."
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13289
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13290
    |redBits greenBits blueBits alphaBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13291
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13292
    samplesPerPixel >= 4 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13293
        redBits := bitsPerSample at:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13294
        greenBits := bitsPerSample at:2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13295
        blueBits := bitsPerSample at:3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13296
        alphaBits := bitsPerSample at:4.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13297
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13298
        ^ (pixel bitShift:(redBits + greenBits + blueBits) negated)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13299
           bitAnd:(1 bitShift:alphaBits)-1
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13300
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13301
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13302
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13303
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13304
    "Created: 8.6.1996 / 09:44:51 / cg"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13305
    "Modified: 10.6.1996 / 14:59:05 / cg"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13306
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13307
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13308
alphaMaskForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13309
    "return the mask used with translation from pixelValues to alphaBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13310
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13311
    |alphaBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13312
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13313
    samplesPerPixel >= 4 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13314
        alphaBits := bitsPerSample at:4.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13315
        ^ (1 bitShift:alphaBits)-1
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13316
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13317
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13318
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13319
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13320
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13321
alphaShiftForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13322
    "return the shift amount used with translation from pixelValues to alphaBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13323
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13324
    |redBits greenBits blueBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13325
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13326
    samplesPerPixel >= 3 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13327
        redBits := bitsPerSample at:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13328
        greenBits := bitsPerSample at:2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13329
        blueBits := bitsPerSample at:3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13330
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13331
        ^ (greenBits + blueBits + redBits) negated
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13332
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13333
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13334
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13335
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13336
3813
662c6386828e ascentOn:
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
 13337
ascentOn:aGC
662c6386828e ascentOn:
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
 13338
    "I will not draw myself above the baseline"
662c6386828e ascentOn:
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
 13339
662c6386828e ascentOn:
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
 13340
    ^ 0
662c6386828e ascentOn:
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
 13341
!
662c6386828e ascentOn:
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
 13342
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13343
averageColor
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13344
    "return the average color of the image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13345
     This usually only makes sense for textures and patterns
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13346
     (i.e. to compute shadow & light colors for viewBackgrounds).
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 13347
     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
 13348
     a subImage - i.e. use Image>>averageColorIn: on a smaller rectangle"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13349
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13350
    ^ self averageColorIn:(0@0 corner:(width-1)@(height-1))
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13351
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13352
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13353
averageColorIn:aRectangle
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13354
    "return the images average color in an area.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13355
     The implementation below is slow - so you may want to
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13356
     create tuned versions for DepthXImage if you plan to do
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13357
     heavy image processing ...
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13358
     (also, creating tuned versions of the enumeration messages helps a lot)"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13359
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13360
    |x0 "{ Class:SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13361
     y0 "{ Class:SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13362
     x1 "{ Class:SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13363
     y1 "{ Class:SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13364
     sumRed sumGreen sumBlue n|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13365
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13366
    sumRed := sumGreen := sumBlue := 0.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13367
    y0 := aRectangle top.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13368
    y1 := aRectangle bottom.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13369
    x0 := aRectangle left.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13370
    x1 := aRectangle right.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13371
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13372
    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
 13373
    mask isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13374
        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
 13375
            sumRed := sumRed + colorAtXY red.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13376
            sumGreen := sumGreen + colorAtXY green.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13377
            sumBlue := sumBlue + colorAtXY blue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13378
        ].
3761
44b96cd84bb8 ignore masked pixels when computing the average
Claus Gittinger <cg@exept.de>
parents: 3760
diff changeset
 13379
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13380
        "/ masked pixels are not counted.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13381
        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
 13382
            (mask pixelAtX:x y:y) == 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13383
                n := n - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13384
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13385
                sumRed := sumRed + colorAtXY red.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13386
                sumGreen := sumGreen + colorAtXY green.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13387
                sumBlue := sumBlue + colorAtXY blue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13388
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13389
        ].
3761
44b96cd84bb8 ignore masked pixels when computing the average
Claus Gittinger <cg@exept.de>
parents: 3760
diff changeset
 13390
    ].
44b96cd84bb8 ignore masked pixels when computing the average
Claus Gittinger <cg@exept.de>
parents: 3760
diff changeset
 13391
    n == 0 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13392
        "/ all masked
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13393
        ^ Color black
3761
44b96cd84bb8 ignore masked pixels when computing the average
Claus Gittinger <cg@exept.de>
parents: 3760
diff changeset
 13394
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13395
    ^ Color red:(sumRed / n) green:(sumGreen / n) blue:(sumBlue / n)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13396
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13397
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13398
bitsPerPixel
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13399
    "return the number of bits per pixel"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13400
5926
95dab34aeea2 changed: #bitsPerPixel
Stefan Vogel <sv@exept.de>
parents: 5919
diff changeset
 13401
    ^ bitsPerSample sum
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13402
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13403
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13404
bitsPerRow
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13405
    "return the number of bits in one scanline of the image"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13406
3868
e47cf114c824 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
 13407
    ^ width * (self bitsPerPixel).
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13408
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13409
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13410
blackComponentOfCMYK:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13411
    "if the receiver is a cmyk-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13412
     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
 13413
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13414
    samplesPerPixel == 4 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13415
        "/ assume that the cyan bits are the leftMost bits (cmyk)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13416
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 13417
        (#[8 8 8 8] isSameSequenceAs:bitsPerSample) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13418
            ^ 100.0 / 255 * (pixel bitAnd:16rFF)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13419
        ]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13420
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13421
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13422
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13423
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 13424
    "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
 13425
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13426
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13427
blueBitsOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13428
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13429
     return the blue bits of a pixelValue as integer 0..maxBlueValue.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13430
     MaxGreenValue is of course the largest integer representable by the number
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13431
     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
 13432
     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
 13433
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13434
    |blueBits|
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13435
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13436
    samplesPerPixel >= 3 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13437
        blueBits := bitsPerSample at:3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13438
        ^ 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
 13439
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13440
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13441
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13442
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13443
    "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
 13444
    "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
 13445
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13446
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13447
blueComponentOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13448
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13449
     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
 13450
     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
 13451
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 13452
    |blueBits  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 13453
     s         "{ Class: SmallInteger }"|
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13454
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13455
    samplesPerPixel >= 3 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13456
        "/ assume that the red bits are the leftMost bits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13457
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13458
        blueBits := bitsPerSample at:3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13459
        blueBits == 0 ifTrue:[^ 0].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13460
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13461
        s := (1 bitShift:blueBits) - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13462
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13463
        ^ 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
 13464
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13465
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13466
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13467
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13468
    "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
 13469
    "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
 13470
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13471
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13472
blueMaskForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13473
    "return the mask used with translation from pixelValues to blueBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13474
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13475
    |blueBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13476
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13477
    samplesPerPixel >= 3 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13478
        blueBits := bitsPerSample at:3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13479
        ^ (1 bitShift:blueBits)-1
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13480
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13481
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13482
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13483
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13484
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13485
blueShiftForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13486
    "return the shift amount used with translation from pixelValues to blueBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13487
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13488
    samplesPerPixel >= 3 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13489
        ^ 0
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13490
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13491
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13492
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13493
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13494
680
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 13495
bounds
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 13496
    "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
 13497
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 13498
    ^ 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
 13499
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 13500
    "Created: 13.5.1996 / 10:27:06 / cg"
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 13501
!
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 13502
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13503
brightness
6755
cee1206f74db class: Image
Claus Gittinger <cg@exept.de>
parents: 6653
diff changeset
 13504
    "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
 13505
     This usually only makes sense for textures and patterns
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13506
     (i.e. to compute shadow & light colors for viewBackgrounds).
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 13507
     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
 13508
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13509
    ^ (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
 13510
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13511
    "Modified: 8.6.1996 / 08:46:46 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13512
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13513
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13514
bytesPerRow
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13515
    "return the number of bytes in one scanline of the image"
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
    |bitsPerRow bytesPerRow|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13518
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13519
    bitsPerRow := width * (self bitsPerPixel).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13520
    bytesPerRow := bitsPerRow // 8.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13521
    ((bitsPerRow \\ 8) ~~ 0) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13522
        bytesPerRow := bytesPerRow + 1
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13523
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13524
    ^ bytesPerRow
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13525
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13526
1993
b3cf63f64e15 added query for padded bytesPerLine
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
 13527
bytesPerRowPaddedTo:padding
b3cf63f64e15 added query for padded bytesPerLine
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
 13528
    "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
 13529
     if scanlines are to be padded to padding-bits."
b3cf63f64e15 added query for padded bytesPerLine
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
 13530
2005
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
 13531
    ^ self class
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13532
        bytesPerRowForWidth:width depth:(self bitsPerPixel) padding:padding
1993
b3cf63f64e15 added query for padded bytesPerLine
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
 13533
!
b3cf63f64e15 added query for padded bytesPerLine
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
 13534
1935
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 13535
center
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 13536
    "for compatibility with GC protocol - return the centerPoint"
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 13537
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 13538
    ^ (width // 2) @ (height // 2)
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 13539
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 13540
    "Created: 22.10.1997 / 23:52:40 / cg"
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 13541
!
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 13542
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13543
colorFromValue:pixelValue
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13544
    "given a pixel value, return the corresponding color.
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13545
     Pixel values start with 0.
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13546
     The implementation below is generic and slow
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13547
     - 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
 13548
5126
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
 13549
    |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
 13550
     numRedBits numGreenBits numBlueBits numAlphaBits|
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 13551
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 13552
    p := photometric.
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 13553
    p isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13554
        colorMap notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13555
            p := #palette
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13556
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13557
            "/ 'Image [warning]: no photometric - assume greyscale' infoPrintCR
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13558
            p := #blackIs0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13559
        ]
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 13560
    ].
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 13561
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 13562
    p == #blackIs0 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13563
        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13564
        ^ Color gray:(pixelValue * (100 / maxPixel)).
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13565
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13566
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 13567
    p == #whiteIs0 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13568
        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13569
        ^ 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
 13570
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13571
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 13572
    p == #palette ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13573
        pixelValue >= colorMap size ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13574
            ^ Color black
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13575
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13576
        clr := colorMap at:(pixelValue + 1).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13577
        clr isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13578
            ^ Color black.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13579
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13580
        ^ clr.
804
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
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 13583
    p == #rgb ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13584
        r := self redBitsOf:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13585
        g := self greenBitsOf:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13586
        b := self blueBitsOf:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13587
        "/ scale...
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13588
        numRedBits := bitsPerSample at:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13589
        numGreenBits := bitsPerSample at:2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13590
        numBlueBits := bitsPerSample at:3.
7595
c77d718d3d94 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7573
diff changeset
 13591
        (r ~~ 0) ifTrue:[ r := 100 / ((1 bitShift:numRedBits) - 1) * r].
c77d718d3d94 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7573
diff changeset
 13592
        (g ~~ 0) ifTrue:[ g := 100 / ((1 bitShift:numGreenBits) - 1) * g].
c77d718d3d94 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7573
diff changeset
 13593
        (b ~~ 0) ifTrue:[ b := 100 / ((1 bitShift:numBlueBits) - 1) * b].
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13594
        ^ Color redPercent:r greenPercent:g bluePercent:b
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 13595
    ].
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 13596
7123
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 13597
    ((p == #rgba) or:[p == #argb]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13598
        r := self redBitsOf:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13599
        g := self greenBitsOf:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13600
        b := self blueBitsOf:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13601
        a := self alphaBitsOf:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13602
        "/ scale...
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13603
        numRedBits := bitsPerSample at:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13604
        numGreenBits := bitsPerSample at:2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13605
        numBlueBits := bitsPerSample at:3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13606
        numAlphaBits := bitsPerSample at:4.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13607
        (r == 0) ifFalse:[ r := (100 / ((1 bitShift:numRedBits)-1) * r)].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13608
        (g == 0) ifFalse:[ g := (100 / ((1 bitShift:numGreenBits)-1) * g)].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13609
        (b == 0) ifFalse:[ b := (100 / ((1 bitShift:numBlueBits)-1) * b)].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13610
        (a == 0) ifFalse:[ a := (100 / ((1 bitShift:numAlphaBits)-1) * a)].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13611
        ^ 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
 13612
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13613
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13614
    p == #cmyk ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13615
        c := self cyanComponentOfCMYK:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13616
        m := self magentaComponentOfCMYK:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13617
        y := self yellowComponentOfCMYK:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13618
        k := self blackComponentOfCMYK:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13619
        ^ 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
 13620
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13621
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13622
    p == #cmy ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13623
        c := self cyanComponentOfCMY:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13624
        m := self magentaComponentOfCMY:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13625
        y := self yellowComponentOfCMY:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13626
        ^ Color cyan:c magenta:m yellow:y.
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13627
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13628
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13629
    self error:'invalid (unsupported) photometric'
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13630
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 13631
    "Created: / 08-06-1996 / 08:46:18 / cg"
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 13632
    "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
 13633
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13634
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13635
cyanComponentOfCMY:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13636
    "if the receiver is a cmy-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13637
     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
 13638
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13639
    samplesPerPixel == 3 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13640
        "/ assume that the cyan bits are the leftMost bits (cmy)
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 13641
        (#[8 8 8] isSameSequenceAs:bitsPerSample)ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13642
            ^ 100.0 / 255 * ((pixel bitShift:-16) bitAnd:16rFF)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13643
        ]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13644
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13645
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13646
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13647
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 13648
    "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
 13649
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13650
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13651
cyanComponentOfCMYK:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13652
    "if the receiver is a cmyk-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13653
     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
 13654
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13655
    samplesPerPixel == 4 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13656
        "/ assume that the cyan bits are the leftMost bits (cmyk)
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 13657
        (#[8 8 8 8] isSameSequenceAs:bitsPerSample)ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13658
            ^ 100.0 / 255 * ((pixel bitShift:-24) bitAnd:16rFF)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13659
        ]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13660
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13661
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13662
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13663
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 13664
    "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
 13665
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13666
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13667
greenBitsOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13668
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13669
     return the green bits of a pixelValue as integer 0..maxGreenValue.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13670
     MaxGreenValue is of course the largest integer representable by the number
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13671
     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
 13672
     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
 13673
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13674
    |blueBits greenBits|
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13675
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13676
    samplesPerPixel >= 3 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13677
        greenBits := bitsPerSample at:2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13678
        blueBits := bitsPerSample at:3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13679
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13680
        ^ (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
 13681
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13682
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13683
    self subclassResponsibility
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
    "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
 13686
    "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
 13687
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13688
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13689
greenComponentOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13690
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13691
     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
 13692
     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
 13693
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 13694
    |greenBits "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 13695
     blueBits  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 13696
     s         "{ Class: SmallInteger }"|
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13697
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13698
    samplesPerPixel >= 3 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13699
        "/ assume that the red bits are the leftMost bits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13700
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13701
        greenBits := bitsPerSample at:2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13702
        greenBits == 0 ifTrue:[^ 0].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13703
        blueBits := bitsPerSample at:3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13704
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13705
        s := (1 bitShift:greenBits) - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13706
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13707
        ^ 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
 13708
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13709
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13710
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13711
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13712
    "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
 13713
    "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
 13714
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13715
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13716
greenMaskForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13717
    "return the mask used with translation from pixelValues to greenBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13718
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13719
    |greenBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13720
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13721
    samplesPerPixel >= 3 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13722
        greenBits := bitsPerSample at:2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13723
        ^ (1 bitShift:greenBits)-1
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13724
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13725
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13726
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13727
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13728
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13729
greenShiftForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13730
    "return the shift amount used with translation from pixelValues to greenBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13731
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 13732
    |greenBits|
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13733
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13734
    samplesPerPixel >= 3 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13735
        greenBits := bitsPerSample at:3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13736
        ^ greenBits negated
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13737
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13738
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13739
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13740
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13741
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13742
heightOn:aGC
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13743
    "return my height, if displayed on aGC;
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13744
     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
 13745
     return the pixel-height"
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13746
680
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 13747
    ^ height
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13748
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13749
    "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
 13750
    "Modified: 13.5.1996 / 10:26:36 / cg"
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13751
!
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13752
3700
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 13753
isDithered
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 13754
    "for compatibility with color protocol"
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 13755
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 13756
    ^ false
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 13757
!
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 13758
3507
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 13759
isGrayscaleImage
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 13760
    ^ (photometric ~= #palette)
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 13761
      and:[photometric ~= #rgb]
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 13762
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 13763
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 13764
    "Created: 22.4.1997 / 14:12:02 / cg"
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 13765
!
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 13766
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13767
isImage
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13768
    "return true, if the receiver is some kind of image;
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13769
     true is returned here - the method is redefined from Object."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13770
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13771
    ^ true
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13772
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13773
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13774
isImageOrForm
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13775
    "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
 13776
     true is returned here - the method is redefined from Object."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13777
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13778
    ^ true
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13779
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13780
1630
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 13781
isMask
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 13782
    ^ false
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 13783
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 13784
    "Created: 22.4.1997 / 14:12:02 / cg"
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 13785
!
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 13786
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13787
magentaComponentOfCMY:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13788
    "if the receiver is a cmy-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13789
     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
 13790
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13791
    samplesPerPixel == 3 ifTrue:[
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 13792
        (#[8 8 8] isSameSequenceAs:bitsPerSample)ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13793
            ^ 100.0 / 255 * ((pixel bitShift:-8) bitAnd:16rFF)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13794
        ]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13795
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13796
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13797
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13798
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 13799
    "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
 13800
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13801
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13802
magentaComponentOfCMYK:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13803
    "if the receiver is a cmyk-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13804
     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
 13805
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13806
    samplesPerPixel == 4 ifTrue:[
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 13807
        (#[8 8 8 8] isSameSequenceAs:bitsPerSample)ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13808
            ^ 100.0 / 255 * ((pixel bitShift:-16) bitAnd:16rFF)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13809
        ]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13810
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13811
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13812
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13813
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 13814
    "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
 13815
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13816
7596
9e63984bd73f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7595
diff changeset
 13817
nColorsUsed
9e63984bd73f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7595
diff changeset
 13818
    ^ self realUsedValues size
9e63984bd73f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7595
diff changeset
 13819
!
9e63984bd73f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7595
diff changeset
 13820
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 13821
pixelArraySpecies
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 13822
    "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
 13823
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 13824
    self depth <= 8 ifTrue:[^ ByteArray].
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 13825
    "/ (d := self depth) <= 8 ifTrue:[^ ByteArray].
6648
dc88bb5f9231 class: Image
Claus Gittinger <cg@exept.de>
parents: 6624
diff changeset
 13826
    "/ d <= 16 ifTrue:[^ WordArray].
dc88bb5f9231 class: Image
Claus Gittinger <cg@exept.de>
parents: 6624
diff changeset
 13827
    "/ ^ IntegerArray
dc88bb5f9231 class: Image
Claus Gittinger <cg@exept.de>
parents: 6624
diff changeset
 13828
    ^ Array
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 13829
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 13830
    "Modified: / 31-01-2017 / 14:52:42 / stefan"
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 13831
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 13832
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13833
realColorMap
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13834
    "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
 13835
     For palette images, this is the internal colormap;
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13836
     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
 13837
     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
 13838
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13839
    |d nEntries "{ Class: SmallInteger }"
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13840
     colorArray|
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13841
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13842
    photometric == #palette ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13843
        ^ colorMap asArray
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13844
    ].
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13845
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13846
    d := self depth.
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13847
    d > 12 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13848
        self error:'deep palette images not supported'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13849
        ^ nil.
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13850
    ].
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13851
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13852
    nEntries := 1 bitShift:d.
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13853
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13854
    colorArray := Array new:nEntries.
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13855
    1 to:nEntries do:[:idx |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13856
        colorArray at:idx put:(self colorFromValue:(idx-1)).
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13857
    ].
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13858
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13859
    ^ colorArray
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13860
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13861
    "Created: 11.7.1996 / 20:20:35 / cg"
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13862
    "Modified: 11.7.1996 / 20:49:21 / cg"
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13863
!
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13864
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13865
realUsedColors
3964
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 13866
    "return a collection of colors which are really used in the receiver.
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 13867
     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
 13868
     (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
 13869
6379
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
 13870
    ^ self realUsedValues collect:[:pixel | self colorFromValue:pixel] as:Set
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13871
!
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13872
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13873
realUsedValues
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13874
    "return a collection of color values used in the receiver.
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 13875
     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
 13876
     of the image.
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13877
     This is a general and therefore slow implementation; subclasses
3964
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 13878
     may want to redefine this method for more performance.
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 13879
     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
 13880
     (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
 13881
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13882
    |set last|
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13883
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13884
    set := IdentitySet new.
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13885
    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
 13886
        pixel ~~ last ifTrue:[
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 13887
            set add:pixel.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 13888
            last := pixel.
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 13889
        ]
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13890
    ].
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13891
    ^ set
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13892
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13893
    "
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 13894
     (Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') usedValues
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 13895
     (Image fromFile:'libtool/bitmaps/SBrowser.xbm') usedValues
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13896
    "
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13897
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13898
    "Modified: / 29.7.1998 / 21:29:44 / cg"
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13899
!
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13900
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13901
redBitsOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13902
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13903
     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
 13904
     MaxRedValue is the largest integer representable by the number
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13905
     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
 13906
     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
 13907
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13908
    |redBits greenBits blueBits|
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13909
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13910
    samplesPerPixel >= 3 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13911
        redBits := bitsPerSample at:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13912
        greenBits := bitsPerSample at:2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13913
        blueBits := bitsPerSample at:3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13914
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13915
        ^ (pixel bitShift:(greenBits + blueBits) negated)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13916
           bitAnd:(1 bitShift:redBits)-1
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13917
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13918
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13919
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13920
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13921
    "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
 13922
    "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
 13923
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13924
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13925
redComponentOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13926
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13927
     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
 13928
     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
 13929
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 13930
    |redBits   "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 13931
     greenBits "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 13932
     blueBits  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 13933
     s         "{ Class: SmallInteger }"|
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13934
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13935
    samplesPerPixel >= 3 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13936
        "/ assume that the red bits are the leftMost bits
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13937
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13938
        redBits := bitsPerSample at:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13939
        redBits == 0 ifTrue:[^ 0].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13940
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13941
        greenBits := bitsPerSample at:2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13942
        blueBits := bitsPerSample at:3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13943
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13944
        s := (1 bitShift:redBits) - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13945
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13946
        ^ 100.0 / s *
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13947
          ((pixel bitShift:(greenBits + blueBits) negated)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13948
           bitAnd:(1 bitShift:redBits)-1)
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13949
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13950
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13951
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13952
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13953
    "Created: 8.6.1996 / 08:45:30 / cg"
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 13954
    "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
 13955
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13956
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13957
redMaskForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13958
    "return the mask used with translation from pixelValues to redBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13959
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13960
    |redBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13961
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13962
    samplesPerPixel >= 3 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13963
        redBits := bitsPerSample at:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13964
        ^ (1 bitShift:redBits)-1
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13965
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13966
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13967
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13968
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13969
    "Created: 8.6.1996 / 09:44:51 / cg"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13970
    "Modified: 10.6.1996 / 14:59:05 / cg"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13971
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13972
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13973
redShiftForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13974
    "return the shift amount used with translation from pixelValues to redBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13975
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13976
    |greenBits blueBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13977
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13978
    samplesPerPixel >= 3 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13979
        greenBits := bitsPerSample at:2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13980
        blueBits := bitsPerSample at:3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13981
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13982
        ^ (greenBits + blueBits) negated
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13983
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13984
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13985
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13986
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13987
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13988
rgbFromValue:pixelValue
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13989
    "given a pixel value, return the corresponding 24bit rgbValue (rrggbb, red is MSB).
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13990
     Pixel value is in 0..2^depth - 1.
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13991
     The implementation below is generic and slow
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13992
     - this method is typically redefined in subclasses."
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13993
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13994
    |p maxPixel clr r g b c m y k|
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13995
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13996
    p := photometric.
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13997
    p isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13998
        colorMap notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 13999
            p := #palette
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14000
        ] ifFalse:[
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14001
"/            'Image [warning]: no photometric - assume greyscale' infoPrintCR
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14002
            p := #blackIs0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14003
        ]
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14004
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14005
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14006
    p == #blackIs0 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14007
        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14008
        b := pixelValue * 255 // maxPixel.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14009
        ^ (((b bitShift:8) bitOr:b) bitShift:8) bitOr:b
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14010
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14011
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14012
    p == #whiteIs0 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14013
        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14014
        b := 255 - (pixelValue * 255 // maxPixel).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14015
        ^ (((b bitShift:8) bitOr:b) bitShift:8) bitOr:b
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14016
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14017
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14018
    p == #palette ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14019
        pixelValue >= colorMap size ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14020
            ^ 0 "/ black
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14021
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14022
        clr := colorMap at:(pixelValue + 1).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14023
        clr isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14024
            ^ 0 "/ black
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14025
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14026
        ^ clr rgbValue.
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14027
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14028
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14029
    p == #rgb ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14030
        r := self redBitsOf:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14031
        g := self greenBitsOf:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14032
        b := self blueBitsOf:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14033
        "/ must scale to byte value...
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14034
        r := r bitShift:(8 - (bitsPerSample at:1)).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14035
        g := g bitShift:(8 - (bitsPerSample at:2)).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14036
        b := b bitShift:(8 - (bitsPerSample at:3)).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14037
        ^ (((r bitShift:8) bitOr:g) bitShift:8) bitOr:b
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14038
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14039
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14040
    p == #cmyk ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14041
        c := self cyanComponentOfCMYK:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14042
        m := self magentaComponentOfCMYK:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14043
        y := self yellowComponentOfCMYK:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14044
        k := self blackComponentOfCMYK:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14045
        ^ (Color cyan:c magenta:m yellow:y black:k) rgbValue.
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14046
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14047
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14048
    p == #cmy ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14049
        c := self cyanComponentOfCMY:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14050
        m := self magentaComponentOfCMY:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14051
        y := self yellowComponentOfCMY:pixelValue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14052
        ^ (Color cyan:c magenta:m yellow:y) rgbValue.
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14053
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14054
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14055
    self error:'invalid (unsupported) photometric'
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14056
!
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 14057
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14058
usedColors
3964
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 14059
    "return a collection of colors used in the receiver.
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 14060
     This looks at the colorMap only if present.
6896
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 14061
     (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
 14062
2311
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 14063
    |colors|
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 14064
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 14065
    colors := self usedColorsMax:4096.
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 14066
    colors isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14067
        self error:'too many colors in image'.
2311
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 14068
    ].
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 14069
    ^ colors
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 14070
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 14071
    "
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 14072
     (Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') usedColors
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 14073
     (Image fromFile:'libtool/bitmaps/SBrowser.xbm') usedColors
2311
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 14074
    "
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 14075
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 14076
    "Modified: / 7.9.1998 / 17:56:12 / cg"
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 14077
!
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 14078
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 14079
usedColorsMax:nMax
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 14080
    "return a collection of colors used in the receiver;
3964
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 14081
     This looks at the colorMap only if present
6896
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 14082
     (as opposed to #realUsedColors, which goes through the pixels of the bitmap).
3964
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 14083
     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
 14084
     (useful when searching rgb images)."
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 14085
2199
ac56b54c59a5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2185
diff changeset
 14086
    |usedValues max colors|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14087
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 14088
    photometric == #rgb ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14089
        usedValues := IdentitySet new.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14090
        self valuesFromX:0 y:0 toX:(width-1) y:(height-1)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14091
          do:[:x :y :pixel |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14092
            usedValues add:pixel.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14093
            usedValues size > nMax ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14094
                "/ too many to be returned here (think of the mass of
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14095
                "/ data to be returned by a 24bit image ... ;-)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14096
                ^ nil
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14097
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14098
        ].
7595
c77d718d3d94 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7573
diff changeset
 14099
"/        colors := usedValues collect:[:pixel | self colorFromValue:pixel].
c77d718d3d94 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7573
diff changeset
 14100
        "/ this code is slightly faster (but wrong for 16-bit images)...
c77d718d3d94 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7573
diff changeset
 14101
        colors := usedValues collect:[:pixel | 
c77d718d3d94 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7573
diff changeset
 14102
                    |r g b|
c77d718d3d94 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7573
diff changeset
 14103
                    r := self redBitsOf:pixel.
c77d718d3d94 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7573
diff changeset
 14104
                    g := self greenBitsOf:pixel.
c77d718d3d94 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7573
diff changeset
 14105
                    b := self blueBitsOf:pixel.
c77d718d3d94 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7573
diff changeset
 14106
                    "/ must scale to byte value...
c77d718d3d94 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7573
diff changeset
 14107
                    r := r bitShift:(8 - (bitsPerSample at:1)).
c77d718d3d94 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7573
diff changeset
 14108
                    g := g bitShift:(8 - (bitsPerSample at:2)).
c77d718d3d94 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7573
diff changeset
 14109
                    b := b bitShift:(8 - (bitsPerSample at:3)).
c77d718d3d94 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7573
diff changeset
 14110
                    Color redByte:r greenByte:g blueByte:b
c77d718d3d94 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7573
diff changeset
 14111
                 ].
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14112
        ^ colors.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 14113
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 14114
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14115
    usedValues := self usedValues asArray.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 14116
    photometric == #palette ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14117
        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
 14118
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14119
        "/ (photometric == #blackIs0 or:[photometric == #whiteIs0])
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14120
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14121
        max := (1 bitShift:self depth) - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14122
        colors :=  usedValues collect:[:val | (Color gray:(100 * val / max ))] as:Set.
6037
eea2343b0b1e Refactoring:
Stefan Vogel <sv@exept.de>
parents: 5956
diff changeset
 14123
    ].
eea2343b0b1e Refactoring:
Stefan Vogel <sv@exept.de>
parents: 5956
diff changeset
 14124
    ^ colors
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14125
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14126
    "
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 14127
     (Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') usedColors
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 14128
     (Image fromFile:'libtool/bitmaps/SBrowser.xbm') usedColors
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14129
    "
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
 14130
2311
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 14131
    "Created: / 7.9.1998 / 17:54:17 / cg"
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 14132
    "Modified: / 7.9.1998 / 17:56:21 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14133
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14134
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14135
usedValues
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14136
    "return a collection of color values used in the receiver.
7511
ce7b0b92416e #OTHER by mawalch
mawalch
parents: 7494
diff changeset
 14137
     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
 14138
     of the image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14139
     This is a general and therefore slow implementation; subclasses
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14140
     may want to redefine this method for more performance."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14141
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 14142
    ^ self realUsedValues
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14143
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14144
    "
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 14145
     (Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') usedValues
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 14146
     (Image fromFile:'lib tool/bitmaps/SBrowser.xbm') usedValues
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14147
    "
2206
8bf0549762b8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2205
diff changeset
 14148
8bf0549762b8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2205
diff changeset
 14149
    "Modified: / 29.7.1998 / 21:29:44 / cg"
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 14150
!
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 14151
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14152
valueFromColor:color
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14153
    "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
 14154
     Non-representable colors return nil."
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14155
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 14156
    |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
 14157
5051
492727d3e5f3 oops valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 5037
diff changeset
 14158
    color colorId notNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14159
        color == Color noColor ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14160
            ^ nil "/ mask
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14161
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14162
        color device isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14163
            ^ color colorId
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14164
        ]
5051
492727d3e5f3 oops valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 5037
diff changeset
 14165
    ].
5037
2e515c9ee849 changed #valueFromColor:
Claus Gittinger <cg@exept.de>
parents: 4998
diff changeset
 14166
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14167
    photometric == #whiteIs0 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14168
        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14169
        ^ maxPixel - (color brightness * maxPixel) rounded.
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14170
    ].
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14171
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14172
    photometric == #blackIs0 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14173
        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14174
        ^ (color brightness * maxPixel) rounded.
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14175
    ].
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14176
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14177
    photometric == #palette ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14178
        colorMap isNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14179
            "/ same as blackIs0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14180
            maxPixel := (1 bitShift:self bitsPerPixel) - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14181
            ^ (color brightness * maxPixel) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14182
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14183
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14184
        pixel := colorMap indexOf:color.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14185
        pixel == 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14186
            "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14187
             the color is not in the images colormap
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14188
            "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14189
            ^ nil
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14190
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14191
        ^ pixel - 1
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14192
    ].
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14193
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14194
    photometric == #rgb ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14195
        samplesPerPixel >= 3 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14196
            redBits := bitsPerSample at:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14197
            greenBits := bitsPerSample at:2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14198
            blueBits := bitsPerSample at:3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14199
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14200
            "/ map r/g/b to 0..255
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14201
            r := (color red / 100.0 * ((1 bitShift:redBits)-1)) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14202
            g := (color green / 100.0 * ((1 bitShift:greenBits)-1)) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14203
            b := (color blue / 100.0 * ((1 bitShift:blueBits)-1)) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14204
            pixel := (((r bitShift:greenBits) + g) bitShift:blueBits) + b.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14205
            ^ pixel
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14206
        ]
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14207
    ].
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14208
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 14209
    photometric == #rgba ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14210
        samplesPerPixel >= 4 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14211
            redBits := bitsPerSample at:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14212
            greenBits := bitsPerSample at:2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14213
            blueBits := bitsPerSample at:3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14214
            alphaBits := bitsPerSample at:4.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14215
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14216
            "/ map r/g/b/a to 0..255
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14217
            r := (color red / 100.0 * ((1 bitShift:redBits)-1)) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14218
            g := (color green / 100.0 * ((1 bitShift:greenBits)-1)) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14219
            b := (color blue / 100.0 * ((1 bitShift:blueBits)-1)) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14220
            a := (color alpha * ((1 bitShift:alphaBits)-1)) rounded.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14221
            pixel := (((((a bitShift:redBits) + r) bitShift:greenBits) + g) bitShift:blueBits) + b.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14222
            ^ pixel
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14223
        ]
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 14224
    ].
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
 14225
    ImageErrorSignal raiseErrorString:'format not supported'.
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14226
    ^ nil
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14227
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 14228
    "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
 14229
!
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14230
4858
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14231
valueFromRGB:rgb
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14232
    "given a color, return the corresponding pixel value.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14233
     Non-representable colors return nil."
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14234
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 14235
    |pixel redBits greenBits blueBits r g b a|
4858
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14236
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14237
    r := rgb bitAnd:16rFF.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14238
    g := (rgb bitShift:-8) bitAnd:16rFF.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14239
    b := (rgb bitShift:-16) bitAnd:16rFF.
7123
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 14240
    a := 255.
4858
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14241
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14242
"/    photometric == #whiteIs0 ifTrue:[
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14243
"/        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14244
"/        ^ maxPixel - (color brightness * maxPixel) rounded.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14245
"/    ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14246
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14247
"/    photometric == #blackIs0 ifTrue:[
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14248
"/        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14249
"/        ^ (color brightness * maxPixel) rounded.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14250
"/    ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14251
"/
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14252
"/    photometric == #palette ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14253
"/        colorMap isNil ifTrue:[
4858
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14254
"/            "/ same as blackIs0
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14255
"/            maxPixel := (1 bitShift:self bitsPerPixel) - 1.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14256
"/            ^ (color brightness * maxPixel) rounded.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14257
"/        ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14258
"/
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14259
"/        pixel := colorMap indexOf:color.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14260
"/        pixel == 0 ifTrue:[
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14261
"/            "
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14262
"/             the color is not in the images colormap
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14263
"/            "
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14264
"/            ^ nil
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14265
"/        ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14266
"/        ^ pixel - 1
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14267
"/    ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14268
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14269
    photometric == #rgb ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14270
        samplesPerPixel >= 3 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14271
            "/ r,g,b  b at low end
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14272
            redBits := bitsPerSample at:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14273
            greenBits := bitsPerSample at:2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14274
            blueBits := bitsPerSample at:3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14275
            pixel := (((r bitShift:greenBits) + g) bitShift:blueBits) + b.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14276
            ^ pixel
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14277
        ]
4858
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14278
    ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14279
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14280
    photometric == #rgba ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14281
        samplesPerPixel >= 4 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14282
            "/ a,r,g,b  b at low end
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14283
            redBits := bitsPerSample at:1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14284
            greenBits := bitsPerSample at:2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14285
            blueBits := bitsPerSample at:3.
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 14286
"/            alphaBits := bitsPerSample at:4.
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14287
            pixel := (((((a bitShift:redBits) + r) bitShift:greenBits) + g) bitShift:blueBits) + b.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14288
            ^ pixel
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14289
        ]
4858
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14290
    ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14291
    ImageErrorSignal raiseErrorString:'format not supported'.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14292
    ^ nil
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14293
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14294
    "Created: / 15-01-2008 / 15:55:08 / cg"
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 14295
    "Modified: / 31-01-2017 / 14:45:00 / stefan"
4858
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14296
!
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14297
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14298
valueFromRedBits:redBits greenBits:greenBits blueBits:blueBits
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14299
    "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
 14300
     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
 14301
     For now, only useful with RGB images"
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14302
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14303
    |pixel numGreenBits numBlueBits|
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14304
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14305
    photometric == #rgb ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14306
        samplesPerPixel >= 3 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14307
            numGreenBits := bitsPerSample at:2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14308
            numBlueBits := bitsPerSample at:3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14309
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14310
            pixel := (((redBits bitShift:numGreenBits) + greenBits) bitShift:numBlueBits) + blueBits.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14311
            ^ pixel
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14312
        ]
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14313
    ].
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14314
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14315
    ImageErrorSignal raiseErrorString:'format not supported'.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14316
    ^ nil
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14317
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14318
    "Modified: / 30.9.1998 / 22:03:50 / cg"
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14319
!
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14320
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 14321
widthOn:aGC
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 14322
    "return my width, if displayed on aGC;
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 14323
     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
 14324
     return the pixel-width"
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 14325
680
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 14326
    ^ width
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 14327
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 14328
    "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
 14329
    "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
 14330
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14331
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14332
yellowComponentOfCMY:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14333
    "if the receiver is a cmy-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14334
     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
 14335
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14336
    samplesPerPixel == 3 ifTrue:[
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 14337
        (#[8 8 8] isSameSequenceAs:bitsPerSample)ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14338
            ^ 100.0 / 255 * (pixel bitAnd:16rFF)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14339
        ]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14340
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14341
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14342
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14343
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14344
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 14345
    "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
 14346
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14347
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14348
yellowComponentOfCMYK:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14349
    "if the receiver is a cmyk-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14350
     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
 14351
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14352
    samplesPerPixel == 4 ifTrue:[
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 14353
        (#[8 8 8 8] isSameSequenceAs:bitsPerSample)ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14354
            ^ 100.0 / 255 * ((pixel bitShift:-8) bitAnd:16rFF)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14355
        ]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14356
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14357
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14358
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14359
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 14360
    "Modified: / 31-01-2017 / 13:19:00 / stefan"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14361
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14362
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14363
!Image methodsFor:'saving on file'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14364
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14365
saveOn:aFileName
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14366
    "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
 14367
     Currently, not all formats may be supported
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 14368
     (see ImageReader subclasses implementing save:onFile:).
3913
25e103c84773 comments
Claus Gittinger <cg@exept.de>
parents: 3912
diff changeset
 14369
     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
 14370
7173
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14371
    ^ self saveOn:aFileName quality:nil
1175
5595569cfbd3 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 1170
diff changeset
 14372
1385
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 14373
    "
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 14374
     |image|
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 14375
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14376
     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
 14377
     image saveOn:'myImage.tiff'.
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 14378
     image saveOn:'myImage.xbm'.
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 14379
     image saveOn:'myImage.xpm'.
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 14380
     image saveOn:'myImage.xwd'.
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 14381
    "
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 14382
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
 14383
    "Modified: 30.6.1997 / 22:06:34 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 14384
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 14385
7173
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14386
saveOn:aFileName quality:qualityPercentOrNil
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14387
    "save the image in aFileName. The suffix of the filename controls the format.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14388
     Currently, not all formats may be supported
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14389
     (see ImageReader subclasses implementing save:onFile:).
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14390
     May raise a signal, if the image cannot be written by the reader."
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14391
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14392
    |suffix readerClass|
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14393
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14394
    "/
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14395
    "/ from the extension, get the imageReader class
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14396
    "/ (which should know how to write images as well)
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14397
    "/
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14398
    suffix := aFileName asFilename suffix.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14399
    readerClass := MIMETypes imageReaderForSuffix:suffix.
7373
61933c223183 added metaData instVar (for free use by image reader)
Claus Gittinger <cg@exept.de>
parents: 7363
diff changeset
 14400
    readerClass isNil ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14401
        "/
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14402
        "/ no known extension - could ask user for the format here.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14403
        "/ currently default to tiff format.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14404
        "/
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14405
        readerClass := self class defaultImageFileWriter.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14406
        '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
 14407
    ].
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14408
    ^ self saveOn:aFileName quality:qualityPercentOrNil using:readerClass
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14409
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14410
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14411
    "
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14412
     |image|
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14413
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14414
     image := Image fromFile:'goodies/bitmaps/RCube.tiff'.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14415
     image saveOn:'myImage.tiff'.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14416
     image saveOn:'myImage.xbm'.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14417
     image saveOn:'myImage.xpm'.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14418
     image saveOn:'myImage.xwd'.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14419
    "
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14420
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14421
    "Modified: 30.6.1997 / 22:06:34 / cg"
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14422
!
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14423
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14424
saveOn:aFileName quality:qualityPercentOrNil using:readerClass
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14425
    "save the receiver using the representation class
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14426
     (which is usually a concrete subclasses of ImageReader).
3913
25e103c84773 comments
Claus Gittinger <cg@exept.de>
parents: 3912
diff changeset
 14427
     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
 14428
7173
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14429
    ^ readerClass save:self onFile:aFileName quality:qualityPercentOrNil
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14430
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14431
    "
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 14432
     |anImage|
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 14433
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14434
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 14435
     anImage saveOn:'myImage.tiff' using:TIFFReader.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14436
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14437
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14438
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14439
     |anImage|
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14440
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14441
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 14442
     anImage saveOn:'myImage.xbm' using:XBMReader.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14443
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14444
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14445
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14446
     |anImage|
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14447
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14448
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14449
     Image cannotRepresentImageSignal handle:[:ex |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14450
        self warn:'cannot save the image in this format'
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14451
     ] do:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14452
        anImage saveOn:'myImage.xbm' using:XBMReader.
7173
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14453
     ]
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14454
    "
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14455
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14456
    "
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14457
     |anImage|
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14458
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14459
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14460
     anImage saveOn:'myImage.xpm' using:XPMReader.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14461
    "
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14462
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14463
    "
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14464
     |anImage|
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14465
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14466
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14467
     anImage saveOn:'myImage.gif' using:GIFReader.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14468
    "
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14469
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14470
    "Modified: 10.4.1997 / 17:49:26 / cg"
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14471
!
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14472
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14473
saveOn:aFileName using:readerClass
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14474
    "save the receiver using the representation class
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14475
     (which is usually a concrete subclasses of ImageReader).
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14476
     May raise a signal, if the image cannot be written by the reader."
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14477
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14478
    ^ readerClass save:self onFile:aFileName quality:nil
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14479
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14480
    "
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14481
     |anImage|
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14482
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14483
     anImage := Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif'.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14484
     anImage saveOn:'myImage.tiff' using:TIFFReader.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14485
     (Depth24Image fromImage:anImage) saveOn:'myImage.jpg' using:JPEGReader.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14486
     anImage saveOn:'myImage50.tiff' quality:50 using:TIFFReader.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14487
     (Depth24Image fromImage:anImage) saveOn:'myImage50.jpg' quality:50 using:JPEGReader.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14488
    "
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14489
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14490
    "
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14491
     |anImage|
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14492
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14493
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14494
     anImage saveOn:'myImage.xbm' using:XBMReader.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14495
    "
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14496
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14497
    "
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14498
     |anImage|
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14499
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14500
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14501
     Image cannotRepresentImageSignal handle:[:ex |
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14502
        self warn:'cannot save the image in this format'
7173
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14503
     ] do:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14504
        anImage saveOn:'myImage.xbm' using:XBMReader.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14505
     ]
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14506
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14507
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14508
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14509
     |anImage|
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14510
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14511
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 14512
     anImage saveOn:'myImage.xpm' using:XPMReader.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14513
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14514
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14515
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14516
     |anImage|
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14517
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14518
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 14519
     anImage saveOn:'myImage.gif' using:GIFReader.
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 14520
    "
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 14521
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14522
    "Modified: 10.4.1997 / 17:49:26 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 14523
! !
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14524
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14525
!Image methodsFor:'screen capture'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14526
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14527
from:aDrawable in:aRectangle
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14528
    "read an image from aDrawable.
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14529
     This may be a device Form, a view or the rootView.
7227
3aaeb922a454 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7224
diff changeset
 14530
     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
 14531
     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
 14532
     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
 14533
     and to read hardcopy images from the screen."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14534
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14535
    | visType
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14536
     x        "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14537
     y        "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14538
     w        "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14539
     h        "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14540
     dstIndex "{ Class: SmallInteger }"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14541
     srcIndex "{ Class: SmallInteger }"
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14542
     srcRow   "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14543
     dstRow   "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14544
     inData tmpData usedPixels mapSize
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14545
     map bytesPerLine
2534
35d91dcc4604 removed unused local
Claus Gittinger <cg@exept.de>
parents: 2533
diff changeset
 14546
     bitOrder spaceBitsPerPixel
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14547
     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
 14548
     bitsR "{ Class: SmallInteger }"
e2c3f84ff31f fixed pixmap readout for win32, where red and green are exchanged
Claus Gittinger <cg@exept.de>
parents: 3518
diff changeset
 14549
     bitsG "{ Class: SmallInteger }"
e2c3f84ff31f fixed pixmap readout for win32, where red and green are exchanged
Claus Gittinger <cg@exept.de>
parents: 3518
diff changeset
 14550
     bitsB "{ Class: SmallInteger }"
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14551
     maskR "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14552
     maskG "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14553
     maskB "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14554
     shR "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14555
     shG "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14556
     shB "{ Class: SmallInteger }"
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
 14557
     shR2 "{ Class: SmallInteger }"
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
 14558
     shG2 "{ Class: SmallInteger }"
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
 14559
     shB2 "{ Class: SmallInteger }"
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14560
     r "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14561
     g "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14562
     b "{ Class: SmallInteger }"
2019
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 14563
     word "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14564
     lword
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14565
     device ddepth isMSB bpp|
2019
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 14566
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 14567
    depth := self depth.
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14568
    bpp := "bitsPerPixel :=" self bitsPerPixel.
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14569
927
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 924
diff changeset
 14570
    device := aDrawable graphicsDevice.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14571
7637
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 14572
    aDrawable isForm ifTrue:[
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 14573
        aDrawable depth == 1 ifTrue:[
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 14574
            "/ a monochrome bitmap ?
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 14575
            visType := #StaticGray.
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 14576
            ddepth := 1.
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 14577
        ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14578
            visType := aDrawable photometric.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14579
            ddepth := aDrawable depth.
7637
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 14580
        ]. 
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14581
        photometric := aDrawable photometric.
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 14582
        samplesPerPixel := ddepth == 24 ifTrue:[3] ifFalse:[1].
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 14583
        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
 14584
    ] ifFalse:[
7637
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 14585
        "get some attributes of the display device"
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 14586
        visType := device visualType.
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 14587
        ddepth := device depth.
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 14588
        "/ kludge for 15bit XFree server
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 14589
        ddepth == 15 ifTrue:[
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 14590
            ddepth := 16
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 14591
        ].
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14592
        (visType == #StaticGray) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14593
            (device blackpixel == 0) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14594
                photometric := #blackIs0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14595
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14596
                photometric := #whiteIs0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14597
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14598
            samplesPerPixel := 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14599
            bpp := "bitsPerPixel :=" ddepth.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14600
            bitsPerSample := ByteArray with:bpp.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14601
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14602
            ((visType == #PseudoColor) or:[(visType == #StaticColor) or:[visType == #GrayScale]]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14603
                photometric := #palette.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14604
                samplesPerPixel := 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14605
                bpp := "bitsPerPixel :=" ddepth.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14606
                bitsPerSample := ByteArray with:bpp.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14607
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14608
                ((visType == #TrueColor) or:[visType == #DirectColor]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14609
                    photometric := #rgb.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14610
                    samplesPerPixel := 3.
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14611
    "/                bpp := "bitsPerPixel :=" depth.
4421
bcc5886c989c form -> image conversion fixes
james
parents: 4420
diff changeset
 14612
    "/                bitsPerSample := ByteArray with:device bitsRed
bcc5886c989c form -> image conversion fixes
james
parents: 4420
diff changeset
 14613
    "/                                       with:device bitsGreen
bcc5886c989c form -> image conversion fixes
james
parents: 4420
diff changeset
 14614
    "/                                       with:device bitsBlue
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14615
                    bpp := "bitsPerPixel :=" 24.
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 14616
                    bitsPerSample := #[8 8 8].
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14617
                ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14618
                    self error:'screen visual not supported'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14619
                    ^ nil
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14620
                ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14621
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14622
        ].
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14623
    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14624
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14625
    "
7227
3aaeb922a454 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7224
diff changeset
 14626
     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
 14627
     offering enough space for 32 bit padding
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14628
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14629
    w := width := aRectangle width.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14630
    h := height := aRectangle height.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14631
    x := aRectangle left.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14632
    y := aRectangle top.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14633
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14634
    "
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14635
     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
 14636
     (its too late when info is present ...)
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14637
    "
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14638
    spaceBitsPerPixel := bpp.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14639
    (bpp > 8) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14640
        spaceBitsPerPixel := 16.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14641
        (bpp > 16) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14642
            spaceBitsPerPixel := 32.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14643
            (bpp > 32) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14644
                spaceBitsPerPixel := bpp.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14645
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14646
        ]
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14647
    ].
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14648
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14649
    bytesPerLine := (w * spaceBitsPerPixel + 31) // 32 * 4.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14650
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14651
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14652
     get the pixels
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14653
    "
1459
84e80b355553 splitted getBitsFrom into getBitsFromPixmap
Claus Gittinger <cg@exept.de>
parents: 1446
diff changeset
 14654
    aDrawable isForm ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14655
        (aDrawable id isNil and:[aDrawable bits notNil]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14656
            info := Dictionary new
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14657
                        at:#bitsPerPixel put:(aDrawable depth);
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14658
                        at:#byteOrder put:#msbFirst;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14659
                        at:#bitOrder put:#msbFirst;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14660
                        at:#bytesPerLine put:(aDrawable width * aDrawable depth + 7)//8;
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14661
                        yourself.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14662
            inData := aDrawable bits.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14663
        ] ifFalse:[
7637
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 14664
            inData := ByteArray new:(bytesPerLine * height).
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14665
            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
 14666
        ]
1459
84e80b355553 splitted getBitsFrom into getBitsFromPixmap
Claus Gittinger <cg@exept.de>
parents: 1446
diff changeset
 14667
    ] ifFalse:[
7637
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 14668
        inData := ByteArray new:(bytesPerLine * height).
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14669
        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
 14670
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14671
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14672
    bitsPerPixelIn := info at:#bitsPerPixel.
2533
3af95252b1b3 oops - ISMSB was not assigned
Claus Gittinger <cg@exept.de>
parents: 2532
diff changeset
 14673
7637
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 14674
    isMSB := (info at:#byteOrder) == #msbFirst.
2533
3af95252b1b3 oops - ISMSB was not assigned
Claus Gittinger <cg@exept.de>
parents: 2532
diff changeset
 14675
2029
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 14676
    "/
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 14677
    "/ check if bitorder is what I like (msbFirst)
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 14678
    "/
7206
Claus Gittinger <cg@exept.de>
parents: 7191
diff changeset
 14679
    "/ mhmh - that's not needed
2029
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 14680
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 14681
    bitsPerPixelIn < 8 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14682
        bitOrder := info at:#bitOrder.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14683
        bitOrder ~~ #msbFirst ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14684
            inData
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14685
                expandPixels:8
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14686
                width:(inData size)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14687
                height:1
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14688
                into:inData
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14689
                mapping:(ImageReader reverseBits "TODO: reverseBitsForDepth:bitsPerPixelIn").
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14690
        ].
2029
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 14691
    ].
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 14692
396
d088e672be8a handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents: 394
diff changeset
 14693
    "
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14694
     check, if the devices padding is different ..
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14695
     or if the bitsPerPixels are different
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14696
    "
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14697
    bytesPerLineIn := (info at:#bytesPerLine).           "what I got"
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14698
    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
 14699
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 14700
    maskR := info at:#redMask ifAbsent:[0].
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 14701
    maskG := info at:#greenMask ifAbsent:[0].
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 14702
    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
 14703
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14704
    ((bytesPerLine ~~ bytesPerLineIn)
7637
a809c69a2cf4 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7621
diff changeset
 14705
     or:[bitsPerPixelIn ~~ bpp]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14706
        tmpData := inData.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14707
        inData := ByteArray uninitializedNew:(bytesPerLine * height).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14708
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14709
        srcRow := 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14710
        dstRow := 1.
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
        bitsPerPixelIn ~~ bpp ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14713
            "/ for now, only 32 -> 24 is supported
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14714
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14715
            maskR == 0 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14716
                bitsR := device bitsRed.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14717
                bitsG := device bitsGreen.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14718
                bitsB := device bitsBlue.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14719
                maskR := (1 bitShift:bitsR) - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14720
                maskG := (1 bitShift:bitsG) - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14721
                maskB := (1 bitShift:bitsB) - 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14722
                shR := device shiftRed negated.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14723
                shG := device shiftGreen negated.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14724
                shB := device shiftBlue negated.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14725
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14726
                shR := (maskR lowBit - 1) negated.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14727
                bitsR := maskR highBit - maskR lowBit + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14728
                maskR := maskR bitShift:shR.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14729
                shG := (maskG lowBit - 1) negated.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14730
                bitsG := maskG highBit - maskG lowBit + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14731
                maskG := maskG bitShift:shG.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14732
                shB := (maskB lowBit - 1) negated.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14733
                bitsB := maskB highBit - maskB lowBit + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14734
                maskB := maskB bitShift:shB.
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
            shR2 := (8 - bitsR).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14737
            shG2 := (8 - bitsG).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14738
            shB2 := (8 - bitsB).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14739
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14740
            ((bitsPerPixelIn == 32) and:[bpp == 24]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14741
                "/ 'reformatting 32->24...' printNL.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14742
                1 to:h do:[:hi |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14743
                    srcIndex := srcRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14744
                    dstIndex := dstRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14745
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14746
                    1 to:w do:[:wi |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14747
                        lword := tmpData unsignedInt32At:srcIndex MSB:isMSB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14748
                        r := (lword bitShift:shR) bitAnd:maskR.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14749
                        g := (lword bitShift:shG) bitAnd:maskG.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14750
                        b := (lword bitShift:shB) bitAnd:maskB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14751
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14752
                        inData at:dstIndex   put:r.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14753
                        inData at:dstIndex+1 put:g.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14754
                        inData at:dstIndex+2 put:b.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14755
                        srcIndex := srcIndex + 4.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14756
                        dstIndex := dstIndex + 3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14757
                    ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14758
                    dstRow := dstRow + bytesPerLine.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14759
                    srcRow := srcRow + bytesPerLineIn
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14760
                ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14761
            ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14762
                ((bitsPerPixelIn == 16) and:[bpp == 24]) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14763
                    "/ 'reformatting 16->24...' printNL.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14764
                    1 to:h do:[:hi |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14765
                        srcIndex := srcRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14766
                        dstIndex := dstRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14767
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14768
                        1 to:w do:[:wi |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14769
                            word := tmpData unsignedInt16At:srcIndex MSB:isMSB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14770
                            r := (word bitShift:shR) bitAnd:maskR.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14771
                            g := (word bitShift:shG) bitAnd:maskG.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14772
                            b := (word bitShift:shB) bitAnd:maskB.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14773
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14774
                            inData at:dstIndex   put:(r bitShift:shR2).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14775
                            inData at:dstIndex+1 put:(g bitShift:shG2).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14776
                            inData at:dstIndex+2 put:(b bitShift:shB2).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14777
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14778
                            srcIndex := srcIndex + 2.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14779
                            dstIndex := dstIndex + 3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14780
                        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14781
                        dstRow := dstRow + bytesPerLine.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14782
                        srcRow := srcRow + bytesPerLineIn
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14783
                    ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14784
                ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14785
                    ('Image [warning]: unsupported depth combination: ' , bitsPerPixelIn printString , ' -> ' ,
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14786
                                                        bpp printString) errorPrintCR.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14787
                    self shouldImplement.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14788
                    ^ nil
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14789
                ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14790
            ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14791
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14792
            "/
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14793
            "/ repad in the buffer
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14794
            "/
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14795
            1 to:h do:[:hi |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14796
                inData replaceFrom:dstRow to:(dstRow + bytesPerLine - 1)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14797
                              with:tmpData startingAt:srcRow.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14798
                dstRow := dstRow + bytesPerLine.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14799
                srcRow := srcRow + bytesPerLineIn
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14800
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14801
        ]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14802
    ] ifFalse:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14803
        (bytesPerLine * height) ~~ inData size ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14804
            tmpData := inData.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14805
            inData := ByteArray uninitializedNew:(bytesPerLine * height).
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14806
            inData replaceFrom:1 to:bytesPerLine * height with:tmpData startingAt:1
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14807
        ]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14808
    ].
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 14809
    self bits:inData.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14810
3864
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
 14811
    "/
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
 14812
    "/  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
 14813
    "/
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
 14814
    photometric == #palette ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14815
        "/
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14816
        "/ 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
 14817
        "/ find out, which colors are in the picture
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14818
        "/
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14819
        usedPixels := inData usedValues.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14820
        mapSize := usedPixels max + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14821
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14822
        "get the palette"
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14823
        map := Array new:mapSize.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14824
        usedPixels do:[:colorIndex |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14825
            |i|
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14826
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14827
            i := colorIndex + 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14828
            device
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14829
                getRGBFrom:colorIndex
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14830
                into:[:r :g :b |
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14831
                    map at:i put:(Color red:r green:g blue:b)
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14832
                ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14833
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14834
        self setColorMap:map.
1644
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 14835
    ].
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 14836
7814
aa4d64730bca #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7795
diff changeset
 14837
    "Modified: / 07-02-1998 / 18:23:07 / cg"
7824
1ecfb677d8d7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7814
diff changeset
 14838
    "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
 14839
!
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14840
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14841
fromScreen:aRectangle
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 14842
    "read an image from the display screen.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 14843
     WARNING: this temporarily grabs the display
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14844
              it may not work from within a buttonMotion
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14845
              (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
 14846
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14847
    ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14848
        fromScreen:aRectangle
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14849
        on:Screen current
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14850
        grab:true
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14851
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 14852
    "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
 14853
!
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14854
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14855
fromScreen:aRectangle on:aDevice
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14856
    "read an image from aDevices display screen.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14857
     Since I have no other displays, only the MonoChrome, StaticGrey
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14858
     and PseudoColor cases have been tested ...
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14859
     (especially True- and DirectColor may be wrong).
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 14860
     Late note: 24bit rgb now also works.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 14861
     WARNING: this temporarily grabs the display
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14862
              it may not work from within a buttonMotion
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14863
              (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
 14864
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14865
    ^ self
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14866
        fromScreen:aRectangle
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14867
        on:aDevice
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14868
        grab:true
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 14869
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 14870
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 14871
     Image fromScreen:((0 @ 0) corner:(100 @ 100)) on:Display
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 14872
     Image fromScreen:((0 @ 0) corner:(500 @ 500)) on:Display
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 14873
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 14874
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 14875
    "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
 14876
!
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14877
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14878
fromScreen:aRectangle on:aDevice grab:doGrab
7227
3aaeb922a454 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7224
diff changeset
 14879
    "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
 14880
     If the doGrab argument is true, the display
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14881
     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
 14882
     shown while the readout is done.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14883
     Since I have no other displays, only the MonoChrome, StaticGrey
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14884
     and PseudoColor cases have been tested ...
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14885
     (especially True- and DirectColor may be wrong).
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 14886
     Late note: 24bit rgb now also works.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 14887
     WARNING: with doGrab true, this temporarily grabs the display
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14888
              and it may not work from within a buttonMotion
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14889
              (use with a false grabArg then)."
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 14890
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 14891
    |curs rootView prevGrab|
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 14892
6613
3b0f0fb40c2c class: Image
Claus Gittinger <cg@exept.de>
parents: 6592
diff changeset
 14893
    curs := nil.
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 14894
"/    doGrab ifTrue:[ |cid|
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14895
"/        curs := Cursor sourceForm:(Image fromFile:'bitmaps/Camera.xbm')
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14896
"/                         maskForm:(Image fromFile:'bitmaps/Camera_m.xbm')
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14897
"/                          hotSpot:16@16.
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14898
"/        curs notNil ifTrue:[
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14899
"/            cid := (curs onDevice:aDevice) id
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14900
"/        ].
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14901
"/    ].
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14902
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14903
    "
7227
3aaeb922a454 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7224
diff changeset
 14904
     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
 14905
    "
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14906
    rootView := aDevice rootView.
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14907
    doGrab ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14908
        prevGrab := aDevice activePointerGrab.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14909
        aDevice grabPointerInView:rootView withCursor:curs.
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14910
    ].
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14911
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14912
    "
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14913
     get the pixels
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14914
    "
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14915
    [
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14916
        self from:rootView in:aRectangle.
3605
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
 14917
    ] ensure:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14918
        doGrab ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14919
            aDevice ungrabPointer.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14920
            prevGrab notNil ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14921
                 aDevice grabPointerInView:prevGrab.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14922
            ]
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14923
        ]
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14924
    ]
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14925
3092
0f1a9ec64574 restore grab after #imageFromUser
ca
parents: 3059
diff changeset
 14926
    "
0f1a9ec64574 restore grab after #imageFromUser
ca
parents: 3059
diff changeset
 14927
     Image fromScreen:((100@100) corner:(200@200)) on:Display grab:false
0f1a9ec64574 restore grab after #imageFromUser
ca
parents: 3059
diff changeset
 14928
     Image fromScreen:((100@100) corner:(200@200)) on:Display grab:true
0f1a9ec64574 restore grab after #imageFromUser
ca
parents: 3059
diff changeset
 14929
    "
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14930
!
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14931
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14932
photometricFromScreen:aDevice
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14933
    "read aDevices display photometric and set my colormap for it.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14934
     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
 14935
     or from an offScreen bitmap, for correct pixel interpretation."
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14937
    |depth visType bitsPerPixel|
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14938
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14939
    "
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14940
     get some attributes of the display device
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14941
    "
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14942
    visType := aDevice visualType.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14943
    depth := aDevice depth.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14944
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14945
    "/ kludge for 15bit XFree server
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14946
    depth == 15 ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14947
        depth := 16
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14948
    ].
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14949
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14950
    (visType == #StaticGray) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14951
        (aDevice blackpixel == 0) ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14952
            photometric := #blackIs0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14953
        ] ifFalse:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14954
            photometric := #whiteIs0
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14955
        ].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14956
        samplesPerPixel := 1.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14957
        bitsPerPixel := depth.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14958
        bitsPerSample := ByteArray with:bitsPerPixel.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14959
        "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14960
         were done, the pixel values are the grey values
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14961
        "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14962
        ^ self
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14963
    ].
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14964
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14965
    ((visType == #TrueColor) or:[visType == #DirectColor]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14966
        photometric := #rgb.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14967
        samplesPerPixel := 3.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14968
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14969
        "/ for now - only support 24bit TrueColor
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14970
        depth ~~ 24 ifTrue:[
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14971
            'IMAGE: unsupported display depth' errorPrintCR.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14972
        ].
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14973
"/                bitsPerPixel := depth.
4115
0e783379a6b0 Use ByteArray for bitsPerSample (255 should be enough ;-)
Stefan Vogel <sv@exept.de>
parents: 4109
diff changeset
 14974
"/                bitsPerSample := ByteArray with:aDevice bitsRed
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14975
"/                                       with:aDevice bitsGreen
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14976
"/                                       with:aDevice bitsBlue
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14977
        bitsPerPixel := 24.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14978
        bitsPerSample := #[8 8 8].
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14979
        "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14980
         were done, the pixel values are the rgb values
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14981
        "
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14982
        ^ self
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14983
    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14984
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14985
    ((visType ~~ #PseudoColor)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14986
    and:[(visType ~~ #StaticColor)
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14987
    and:[visType ~~ #GrayScale]]) ifTrue:[
7522
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14988
        self error:'screen visual not supported'.
b9cefa848775 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
 14989
        ^ nil
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14990
    ].
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14991
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14992
    photometric := #palette.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14993
    samplesPerPixel := 1.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14994
    bitsPerPixel := depth.
4115
0e783379a6b0 Use ByteArray for bitsPerSample (255 should be enough ;-)
Stefan Vogel <sv@exept.de>
parents: 4109
diff changeset
 14995
    bitsPerSample := ByteArray with:bitsPerPixel.
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14996
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14997
    "
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14998
     still need the pixels r/g/b values ...
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14999
    "
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
 15000
    self setColorMap:aDevice colorMap
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15001
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 15002
    "Modified: 11.7.1996 / 11:11:34 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 15003
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 15004
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15005
!Image methodsFor:'virtual anti-aliased'!
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15006
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
 15007
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
 15008
    |isBottom isLeft additionalY workPoint startX endX pixels pixelPos percent distance nearestKey tmp|
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15009
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15010
    isBottom := bottomOrTop sameAs:#bottom.
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15011
    isBottom ifTrue:[
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15012
        additionalY := -1.
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15013
    ] ifFalse:[
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15014
        additionalY := 1.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15015
    ].
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15016
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15017
    isLeft := leftOrRight sameAs:#left.
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15018
    isLeft ifTrue:[
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15019
        workPoint := (xRun - 1)@yRun.
7640
25640118d11f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7637
diff changeset
 15020
        [
25640118d11f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7637
diff changeset
 15021
            ((tempForm pixelAtX:workPoint x y:workPoint y) == 0)
25640118d11f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7637
diff changeset
 15022
            and:[ ((tempForm pixelAtX:workPoint x y:workPoint y + additionalY) == 1) 
25640118d11f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7637
diff changeset
 15023
            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
 15024
        ] whileTrue:[
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15025
            startX := workPoint x.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15026
            endX isNil ifTrue:[endX := workPoint x].
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15027
            workPoint := (workPoint x - 1)@yRun.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15028
        ].
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15029
    ] ifFalse:[
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15030
        workPoint := (xRun + 1)@yRun.
7640
25640118d11f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7637
diff changeset
 15031
        [
25640118d11f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7637
diff changeset
 15032
            ((tempForm pixelAtX:workPoint x y:workPoint y) == 0)
25640118d11f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7637
diff changeset
 15033
            and:[ ((tempForm pixelAtX:workPoint x y:workPoint y + additionalY) == 1) 
25640118d11f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7637
diff changeset
 15034
            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
 15035
        ] whileTrue:[
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15036
            endX := workPoint x.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15037
            startX isNil ifTrue:[startX := workPoint x].
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15038
            workPoint := (workPoint x + 1)@yRun.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15039
        ].
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15040
    ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15041
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15042
    (startX notNil and:[endX notNil]) ifTrue:[
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15043
        startX = endX ifTrue:[
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15044
            self atImageAndMask:startX@yRun putValue:((colorDictionary at:aColor) at:blendStart).
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15045
        ] ifFalse:[
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15046
            pixels := (endX - startX) + 1.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15047
            startX to:endX do:[:x |
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15048
                isLeft ifTrue:[
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15049
                    pixelPos := (x - startX) + 1.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15050
                ] ifFalse:[
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15051
                    pixelPos := (endX - x) + 1.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15052
                ].
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15053
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15054
                percent := (100 / (pixels / pixelPos)) asFloat / 100.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15055
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15056
                (colorDictionary at:aColor) keys do:[:aKey |
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15057
                    nearestKey isNil ifTrue:[
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15058
                        distance := percent dist:aKey.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15059
                        nearestKey := aKey.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15060
                    ] ifFalse:[
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15061
                        tmp := percent dist:aKey.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15062
                        distance > tmp ifTrue:[
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15063
                            distance := tmp.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15064
                            nearestKey := aKey.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15065
                        ].
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15066
                    ].
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15067
                ].
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15068
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15069
                self atImageAndMask:x@yRun putValue:((colorDictionary at:aColor) at:nearestKey).
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15070
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15071
                distance := nil.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15072
                nearestKey := nil.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15073
            ].
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15074
        ].
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15075
    ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15076
!
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15077
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
 15078
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
 15079
    |isLeft isBottom additionalX workPoint startY endY pixels pixelPos percent distance nearestKey tmp|
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15080
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15081
    isLeft := leftOrRight sameAs:#left.
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15082
    isLeft ifTrue:[
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15083
        additionalX := 1.
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15084
    ] ifFalse:[
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15085
        additionalX := -1.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15086
    ].
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15087
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15088
    isBottom := bottomOrTop sameAs:#bottom.
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15089
    isBottom ifTrue:[
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15090
        workPoint := xRun@(yRun + 1).
7640
25640118d11f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7637
diff changeset
 15091
        [
25640118d11f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7637
diff changeset
 15092
            ((tempForm pixelAtX:workPoint x y:workPoint y) == 0) 
25640118d11f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7637
diff changeset
 15093
            and:[ ((tempForm pixelAtX:workPoint x + additionalX y:workPoint y) == 1) 
25640118d11f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7637
diff changeset
 15094
            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
 15095
        ] whileTrue:[
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15096
            endY := workPoint y.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15097
            startY isNil ifTrue:[startY := workPoint y].
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15098
            workPoint := xRun@(workPoint y + 1).
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15099
        ].
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15100
    ] ifFalse:[
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15101
        workPoint := xRun@(yRun - 1).
7640
25640118d11f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7637
diff changeset
 15102
        [
25640118d11f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7637
diff changeset
 15103
            ((tempForm pixelAtX:workPoint x y:workPoint y) == 0) 
25640118d11f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7637
diff changeset
 15104
            and:[ ((tempForm pixelAtX:workPoint x + additionalX y:workPoint y) == 1) 
25640118d11f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7637
diff changeset
 15105
            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
 15106
        ] whileTrue:[
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15107
            startY := workPoint y.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15108
            endY isNil ifTrue:[endY := workPoint y].
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15109
            workPoint := xRun@(workPoint y - 1).
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15110
        ].
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15111
    ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15112
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15113
    (startY notNil and:[endY notNil]) ifTrue:[
7481
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15114
        startY = endY ifTrue:[
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15115
            self atImageAndMask:xRun@startY putValue:((colorDictionary at:aColor) at:blendStart).
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15116
        ] ifFalse:[
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15117
            pixels := (endY - startY) + 1.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15118
            startY to:endY do:[:y |
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15119
                isBottom ifTrue:[
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15120
                    pixelPos := (endY - y) + 1.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15121
                ] ifFalse:[
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15122
                    pixelPos := (y - startY) + 1.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15123
                ].
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15124
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15125
                percent := (100 / (pixels / pixelPos)) asFloat / 100.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15126
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15127
                (colorDictionary at:aColor) keys do:[:aKey |
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15128
                    nearestKey isNil ifTrue:[
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15129
                        distance := percent dist:aKey.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15130
                        nearestKey := aKey.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15131
                    ] ifFalse:[
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15132
                        tmp := percent dist:aKey.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15133
                        distance > tmp ifTrue:[
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15134
                            distance := tmp.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15135
                            nearestKey := aKey.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15136
                        ].
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15137
                    ].
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15138
                ].
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15139
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15140
                self atImageAndMask:xRun@y putValue:((colorDictionary at:aColor) at:nearestKey).
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15141
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15142
                distance := nil.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15143
                nearestKey := nil.
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15144
            ].
47aede177c3a #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 7480
diff changeset
 15145
        ].
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15146
    ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15147
! !
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 15148
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
 15149
!Image class methodsFor:'documentation'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 15150
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 15151
version
6894
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
 15152
    ^ '$Header$'
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
 15153
!
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
 15154
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
 15155
version_CVS
6894
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
 15156
    ^ '$Header$'
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
 15157
! !
3759
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
 15158
6037
eea2343b0b1e Refactoring:
Stefan Vogel <sv@exept.de>
parents: 5956
diff changeset
 15159
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 15160
Image initialize!