Image.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 18 Mar 2016 07:49:36 +0000
branchjv
changeset 7223 bce4cd6c45cd
parent 7214 3ed9ddd4332c
parent 7222 77eae07d014e
child 7226 78d9aa881c26
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7206
Claus Gittinger <cg@exept.de>
parents: 7191
diff changeset
     1
"{ Encoding: utf8 }"
Claus Gittinger <cg@exept.de>
parents: 7191
diff changeset
     2
0
48194c26a46c Initial revision
claus
parents:
diff changeset
     3
"
6
7ee0cfde237d *** empty log message ***
claus
parents: 5
diff changeset
     4
 COPYRIGHT (c) 1991 by Claus Gittinger
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
     5
	      All Rights Reserved
0
48194c26a46c Initial revision
claus
parents:
diff changeset
     6
48194c26a46c Initial revision
claus
parents:
diff changeset
     7
 This software is furnished under a license and may be used
48194c26a46c Initial revision
claus
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
48194c26a46c Initial revision
claus
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
48194c26a46c Initial revision
claus
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
48194c26a46c Initial revision
claus
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
48194c26a46c Initial revision
claus
parents:
diff changeset
    12
 hereby transferred.
48194c26a46c Initial revision
claus
parents:
diff changeset
    13
"
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
    14
"{ Package: 'stx:libview' }"
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
    15
6755
cee1206f74db class: Image
Claus Gittinger <cg@exept.de>
parents: 6653
diff changeset
    16
"{ NameSpace: Smalltalk }"
cee1206f74db class: Image
Claus Gittinger <cg@exept.de>
parents: 6653
diff changeset
    17
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    18
Object subclass:#Image
6284
ebd0dfb1322c cleanup - removed unused instvars
Claus Gittinger <cg@exept.de>
parents: 6256
diff changeset
    19
	instanceVariableNames:'pixelFunction bytes width height bitsPerPixel depth colorMap
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
    20
		maxPixelValue rowByteSize bitsPerSample samplesPerPixel
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
    21
		photometric device deviceForm monoDeviceForm fullColorDeviceForm
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
    22
		mask maskedPixelsAre0 fileName imageSequence'
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
    23
	classVariableNames:'Lobby DitherAlgorithm NumberOfDitherColors
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
    24
		CollectGarbageWhenRunningOutOfColors ImageErrorSignal
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
    25
		ImageNotFoundQuerySignal BadImageFormatQuerySignal
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
    26
		ImageSaveErrorSignal ImageLoadErrorSignal FileCreationErrorSignal
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
    27
		CannotRepresentImageSignal InformationLostQuerySignal
7170
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
    28
		UnrepresentableColorSignal ARGB_A_OFFSET_MACHINE
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
    29
		ARGB_R_OFFSET_MACHINE ARGB_G_OFFSET_MACHINE ARGB_B_OFFSET_MACHINE'
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
    30
	poolDictionaries:''
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
    31
	category:'Graphics-Images'
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    32
!
48194c26a46c Initial revision
claus
parents:
diff changeset
    33
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
    34
!Image class methodsFor:'documentation'!
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    35
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    36
copyright
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    37
"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    38
 COPYRIGHT (c) 1991 by Claus Gittinger
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
    39
	      All Rights Reserved
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    40
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    41
 This software is furnished under a license and may be used
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    42
 only in accordance with the terms of that license and with the
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    43
 inclusion of the above copyright notice.   This software may not
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    44
 be provided or otherwise made available to, or used by, any
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    45
 other person.  No title to or ownership of the software is
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    46
 hereby transferred.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    47
"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    48
!
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    49
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    50
documentation
48194c26a46c Initial revision
claus
parents:
diff changeset
    51
"
6284
ebd0dfb1322c cleanup - removed unused instvars
Claus Gittinger <cg@exept.de>
parents: 6256
diff changeset
    52
    this class provides representation for all kinds of images
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
    53
    (monochrome, greyscale and color) and may finally replace Form.
6166
87e576aea243 class: Image
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
    54
    Depths of 1, 2, 4, 8, 16, 24 and 32 are supported.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    55
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    56
    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
    57
    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
    58
    The data held keeps all information which was originally present,
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    59
    even if the display-device has lower resolution.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    60
    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
    61
    color information.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    62
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    63
    Images may be created manually (by providing a pixel array),
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
    64
    by screen capture, by reading a file (using an ImageReader) or
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
    65
    dynamically computed by a pixelFunction (functional image).
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
    66
6166
87e576aea243 class: Image
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
    67
    This gives you a device independent image.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    68
    For display, a device representation is required, which can be
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
    69
    aquired by sending the 'onDevice:aDevice' message to the image. 
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
    70
    This creates a (possibly dithered) device-form,
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    71
    representing the image using the currently available colors.
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    72
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    73
    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
    74
    (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
    75
    it the message
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
    76
        'monochromeOn:aDevice'.
6284
ebd0dfb1322c cleanup - removed unused instvars
Claus Gittinger <cg@exept.de>
parents: 6256
diff changeset
    77
ebd0dfb1322c cleanup - removed unused instvars
Claus Gittinger <cg@exept.de>
parents: 6256
diff changeset
    78
    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
    79
    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
    80
    with color allocation optimizations and dithering. Nowadays, these are hardly ever needed,
87e576aea243 class: Image
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
    81
    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
    82
    to a device representation.
286
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    83
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    84
    An images pixel interpretation is controlled by the photometric instance variable
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    85
    and (if that is #palette) a colorMap.
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    86
    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
    87
    (and using specialized colorMaps for b&w / greyScale images).
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    88
    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
    89
286
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    90
    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
    91
    which have the file-format knowledge built in.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    92
    There are readers for most common formats available
286
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    93
    (see ImageReader and especially subclasses such as TIFFReader, GIFReader etc.).
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    94
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    95
    File formats are handled by subclasses of ImageReader, which understand
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    96
    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
    97
    to the mapping maintained in the MIMETypes class.
87e576aea243 class: Image
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
    98
    (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
    99
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
   100
    Some algorithms used here (especially dithering & color allocation) are
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   101
    experimental and far from being perfect (some are very slow).
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   102
    For now, the most common cases have been optimized and perform reasonably
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   103
    fast - however, with uncommon depth/visualType combinations, you may
6166
87e576aea243 class: Image
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
   104
    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
   105
    write a specially tuned (inline-C) version for that case.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   106
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   107
    The pixelFunction enables dynamically computed functional images: instead of
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   108
    providing a byteArray containing pixel data, a function is used which maps
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   109
    x/y coordinates to a pixel value (see examples).
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   110
    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
   111
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   112
    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
   113
    (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
   114
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   115
    Dithering can be controlled by the DitherAlgorithm classVariable:
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
   116
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   117
       DitherAlgorithm:
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   118
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   119
       nil                  a simple threshold algorithm
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   120
                            (i.e. for mono, p<0.5 -> black, p>=0.5 -> white)
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   121
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   122
       #pattern             patterned dither
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   123
                            (for p, take dithered color to fill pixel;
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   124
                             uses dithering in color-class)
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   125
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   126
       #error               error diffusion dither (Floyd-Steinberg)
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   127
                            planned - not yet implemented.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   128
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   129
6862
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
   130
    Notice:
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
   131
        the set of attributes and the way they are stored originated initially 
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
   132
        from the need to represent tiff images. These turned out to use a relatively
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
   133
        large set of atributes, of which many are unused in other image formats.
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
   134
        (so it was sufficient).
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
   135
        Later, some VisualWorks compatibility protocol was added (mapped palettes, for
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
   136
        example), and some stuff could well be redefined in simpler ways.
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
   137
        We may do that, if we are bored and there is nothing else to improve... ;-)
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
   138
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   139
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   140
    [instance variables:]
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   141
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   142
        width               <Integer>       the width in pixels
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   143
        height              <Integer>       the height in pixels
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   144
        bytes               <ByteArray>     the full image information
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   145
        photometric         <Symbol>        #rgb, #palette, #blackIs0 or #whiteIs0
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   146
        samplesPerPixel     <Integer>       the number of planes
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   147
        bitsPerSample       <Array>         the number of bits per plane
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   148
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   149
        colorMap            <Array>         only if photometric is #palette;
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   150
                                            maps pixel values to r/g/b values.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   151
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   152
        device              <Workstation>   the device on which deviceForm,
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   153
                                            monoDeviceForm and lowResDeviceForm are
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   154
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   155
        deviceForm          <Form>          the device form which gives the best
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   156
                                            possible aproximation of the image on
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   157
                                            device using standard colors.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   158
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   159
        monoDeviceForm      <Form>          the device form which gives a monochrome
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   160
                                            aproximation of the image on device.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   161
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   162
        fullColorDeviceForm <Form>          the device form which gives the best
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   163
                                            possible aproximation of the image on
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   164
                                            device using private colors.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   165
                                            (not yet implemented)
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   166
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   167
        mask                <ImageMask>     an optional mask;
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   168
                                            if non-nil, only pixels for which the
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   169
                                            corresponding mask bit is non-zero
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   170
                                            are drawn.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   171
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   172
        maskedPixelsAre0    <Boolean>       a hint for image processors and drawers
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   173
                                            if true, masked pixels are known to be
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   174
                                            zero in the pixel bytes.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   175
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   176
        fileName            <String>        the name of the file from which the
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   177
                                            image was loaded - nil otherwise.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   178
                                            Useful for image save functions
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   179
                                            and for the UIPainter utility.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   180
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   181
        imageSequence                       the imageSequence, of which the
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   182
                                            instance is a frame or nil,
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   183
                                            if its not part of a sequence.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   184
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
   185
        bitsPerPixel                        obsolete - not used in ST/X (kept for a while for subclasses)
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   186
        depth                               - these have been added in instVar-slots
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   187
        maxPixelValue                       - according to the ST-80's image class.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   188
        rowByteSize                         - to allow loading of st-80 images
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   189
                                            - (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
   190
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   191
    [class variables:]
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   192
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   193
        Lobby               <Registry>      keeps track of known images
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   194
                                            (for resource freeing with garbage collector)
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   195
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   196
        DitherAlgorithm     <Symbol>        defines how to dither
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   197
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   198
        NumberOfDitherColors <Integer>      defines, how many dither colors to use
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   199
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   200
        FileFormats         <Dictionary>    associates filename extensions to
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   201
                                            image reader classes (now set-up in startup-file)
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   202
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   203
        CollectGarbageWhenRunningOutOfColors
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   204
                            <Boolean>       if true, and we run out of available
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   205
                                            device colors during creation of a
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   206
                                            device image, collect garbage for
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   207
                                            possible image reclamation.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   208
                                            If false, proceed immediately.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   209
                                            Default is true.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   210
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   211
        ImageNotFoundQuerySignal
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   212
                            <QuerySignal>   raised, if an image could not be loaded
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   213
                                            from a file. The parameter is the images
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   214
                                            fileName.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   215
                                            A handler may return a replacement
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   216
                                            image or proceed with nil.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   217
                                            If unhandled, a nil is returned from the
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   218
                                            image creation.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   219
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   220
        BadImageFormatQuerySignal
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   221
                            <QuerySignal>   raised, if an image could not be loaded
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   222
                                            from a file due to a file error or
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   223
                                            unsupported format.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   224
                                            A handler may return a replacement
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   225
                                            image or proceed with nil.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   226
                                            If unhandled, a nil is returned from the
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   227
                                            image creation.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   228
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   229
        ImageSaveErrorSignal
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   230
                            <Signal>        parent of errors below.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   231
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   232
        FileCreationErrorSignal
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   233
                            <Signal>        file could not be created when saving an
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   234
                                            image.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   235
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   236
        CannotRepresentImageSignal
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   237
                            <Signal>        the specified ImageReader cannot represent
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   238
                                            the given image.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   239
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   240
        InformationLostQuerySignal
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   241
                            <Signal>        the specified ImageReader can represent
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   242
                                            the given image, but some information
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   243
                                            (typically color resolution) is lost.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   244
                                            If unhandled, the save proceeds as usual.
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
   245
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
   246
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
   247
    caveat:
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   248
        the information in
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   249
            photometric, bitsPerPixel, bitsPerSample, samplesPerPixel, depth , colorMap and maxPixelValue
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   250
        is partially redundant and its handling stupid (not to say: braindamaged ;-).
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   251
        The only excuse is that it grew over time, had to incorporate various alien/older schemes for
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
   252
        compatibility reasons (mostly coming from tiff format, which was the very first supported format). 
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
   253
        All of the above belongs into the single colorMap which must migrate from
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   254
        a stupid seqColl to a color-aware real colorMap.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   255
        (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
   256
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   257
    todo:
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   258
        support alpha masks
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   259
        cleanup the dithering & conversion code
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   260
        cleanup the color/photometric mess
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   261
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   262
    [See also:]
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   263
        Form Icon ImageReader
611
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   264
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   265
    [author:]
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   266
        Claus Gittinger
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   267
"
649
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   268
!
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   269
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   270
examples
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   271
"
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   272
    reading from a file (many formats are supported):
2645
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   273
    (notice, that the bitmaps directory is searched for along
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   274
     the system path - therefore, you may add your own bitmap
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   275
     directory to the beginning of the path and thus override
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   276
     any default bitmaps, or make certain that your application
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   277
     finds its bitmaps - even if they are in a separate directory)
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   278
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   279
                                                                                        [exBegin]
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   280
        (Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif') inspect
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   281
                                                                                        [exEnd]
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   282
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   283
    better use package relative file names:
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   284
                                                                                        [exBegin]
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   285
        (Image fromFile:'bitmaps/gifImages/garfield.gif' inPackage:'stx:goodies') inspect
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   286
                                                                                        [exEnd]
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   287
    various file formats are supported:
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   288
                                                                                        [exBegin]
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   289
        (Image fromFile:'bitmaps/xpmBitmaps/misc_icons/SmalltalkX_clr.xpm' inPackage:'stx:goodies') inspect
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   290
                                                                                        [exEnd]
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   291
                                                                                        [exBegin]
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   292
        (Image fromFile:'bitmaps/winBitmaps/okSmily_up.bmp' inPackage:'stx:goodies') inspect
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   293
                                                                                        [exEnd]
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   294
7222
matilk
parents: 7210
diff changeset
   295
    drawing
matilk
parents: 7210
diff changeset
   296
                                                                                        [exBegin]
matilk
parents: 7210
diff changeset
   297
        |imageClass image|
matilk
parents: 7210
diff changeset
   298
matilk
parents: 7210
diff changeset
   299
        imageClass := Image implementorForDepth:24.
matilk
parents: 7210
diff changeset
   300
        image      := imageClass width: 100 height: 50.
matilk
parents: 7210
diff changeset
   301
        image bits:(ByteArray new:(image bytesPerRow*50)).
matilk
parents: 7210
diff changeset
   302
        image fillRectangle:(0@0 extent:100@50) withColor:Color yellow.
matilk
parents: 7210
diff changeset
   303
        image drawRectangle:(10@10 extent:20@20) withColor:Color red.
matilk
parents: 7210
diff changeset
   304
        image fillRectangle:(40@20 extent:20@20) withColor:Color green.
matilk
parents: 7210
diff changeset
   305
                                                                                        [exEnd]
matilk
parents: 7210
diff changeset
   306
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   307
    The following examples demonstrate various depth and colorMap variations ...
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   308
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   309
    inline image:
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   310
      default: depth=1 & #blackIs0
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   311
                                                                        [exBegin]
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   312
        (Image 
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   313
            width:8 height:8
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   314
            fromArray:#( 2r11111111
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   315
                         2r10000001
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   316
                         2r10000001
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   317
                         2r10000001
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   318
                         2r10000001
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   319
                         2r10000001
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   320
                         2r10000001
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   321
                         2r11111111 )
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   322
        ) edit
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   323
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   324
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   325
      with #whiteIs0 photometric
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   326
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   327
        ((Image width:8 height:8
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   328
               fromArray:#( 2r11111111
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   329
                            2r10000001
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   330
                            2r10000001
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   331
                            2r10000001
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   332
                            2r10000001
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   333
                            2r10000001
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   334
                            2r10000001
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   335
                            2r11111111 ))
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   336
            photometric:#whiteIs0
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   337
        ) edit
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   338
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   339
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   340
      with a colorMap
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   341
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   342
        ((Image width:8 height:8
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   343
               fromArray:#( 2r11111111
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   344
                            2r10000001
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   345
                            2r10000001
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   346
                            2r10000001
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   347
                            2r10000001
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   348
                            2r10000001
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   349
                            2r10000001
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   350
                            2r11111111 ))
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   351
            colorMap:(Array with:(Color red)
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   352
                            with:(Color yellow))
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   353
        ) edit
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   354
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   355
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   356
      a depth4 greyScale image:
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   357
      (default photometric is #blackIs0)
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   358
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   359
        (Depth4Image
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   360
             width:8
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   361
             height:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   362
             fromArray:#[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   363
                            16r00 16r11 16r22 16r33
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   364
                            16r44 16r55 16r66 16r77
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   365
                            16r88 16r99 16raa 16rbb
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   366
                            16rcc 16rdd 16ree 16rff
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   367
                        ]
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   368
        ) edit
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   369
                                                                        [exEnd]
2645
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   370
      the same, magnified:
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   371
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   372
        ((Depth4Image
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   373
             width:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   374
             height:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   375
             fromArray:#[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   376
                            16r01 16r23
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   377
                            16r45 16r67
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   378
                            16r89 16rab
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   379
                            16rcd 16ref
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   380
                        ])
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   381
            magnifiedBy:30
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   382
        ) edit
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   383
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   384
      the following has the same effect:
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   385
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   386
        ((Image
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   387
             width:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   388
             height:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   389
             depth:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   390
             fromArray:#[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   391
                            16r01 16r23
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   392
                            16r45 16r67
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   393
                            16r89 16rab
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   394
                            16rcd 16ref
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   395
                        ])
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   396
            magnifiedBy:30
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   397
        ) edit
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   398
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   399
      with reverse grey-interpretation:
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   400
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   401
        ((Depth4Image
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   402
             width:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   403
             height:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   404
             fromArray:#[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   405
                            16r01 16r23
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   406
                            16r45 16r67
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   407
                            16r89 16rab
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   408
                            16rcd 16ref
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   409
                        ])
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   410
            photometric:#whiteIs0;
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   411
            magnifiedBy:30
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   412
        ) edit
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   413
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   414
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   415
      with 1-bit-per-pixel rgb interpretation:
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   416
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   417
        ((Depth4Image
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   418
             width:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   419
             height:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   420
             fromArray:#[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   421
                            16r01 16r23
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   422
                            16r45 16r67
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   423
                            16r89 16rab
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   424
                            16rcd 16ref
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   425
                        ])
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   426
            photometric:#rgb;
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   427
            samplesPerPixel:3;
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   428
            bitsPerSample:#(1 1 1);
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   429
            magnifiedBy:30
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   430
        ) edit
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   431
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   432
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   433
      with 1/2/1 rgb interpretation:
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   434
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   435
        ((Depth4Image
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   436
             width:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   437
             height:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   438
             fromArray:#[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   439
                            16r01 16r23
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   440
                            16r45 16r67
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   441
                            16r89 16rab
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   442
                            16rcd 16ref
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   443
                        ])
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   444
            photometric:#rgb;
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   445
            samplesPerPixel:3;
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   446
            bitsPerSample:#(1 2 1);
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   447
            magnifiedBy:30
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   448
        ) edit
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   449
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   450
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   451
      a 2/2/0 rgb image (i.e. no blue):
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   452
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   453
         |i|
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   454
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   455
         i := Depth4Image
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   456
                    width:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   457
                    height:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   458
                    fromArray:#[ 16r01 16r23
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   459
                                 16r45 16r67
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   460
                                 16r89 16rab
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   461
                                 16rcd 16ref ].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   462
         i photometric:#rgb.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   463
         i samplesPerPixel:3.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   464
         i bitsPerSample:#(2 2 0).
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   465
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   466
         i := i magnifiedBy:30.
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   467
         i edit.
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   468
                                                                        [exEnd]
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   469
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   470
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   471
      a 0/0/4 rgb image (i.e. no red or green):
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   472
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   473
         |i|
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   474
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   475
         i := Depth4Image
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   476
                    width:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   477
                    height:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   478
                    fromArray:#[ 16r01 16r23
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   479
                                 16r45 16r67
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   480
                                 16r89 16rab
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   481
                                 16rcd 16ref ].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   482
         i photometric:#rgb.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   483
         i samplesPerPixel:3.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   484
         i bitsPerSample:#(0 0 4).
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   485
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   486
         i := i magnifiedBy:30.
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   487
         i edit.
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   488
                                                                        [exEnd]
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   489
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   490
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   491
      a 2plane greyscale image:
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   492
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   493
        ((Depth2Image
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   494
             width:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   495
             height:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   496
             fromArray:#[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   497
                            4r0123
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   498
                            4r1230
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   499
                            4r2301
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   500
                            4r3012
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   501
                        ])
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   502
            magnifiedBy:30
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   503
        ) edit
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   504
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   505
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   506
      with colors:
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   507
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   508
        ((Depth2Image
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   509
             width:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   510
             height:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   511
             fromArray:#[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   512
                            4r0123
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   513
                            4r1230
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   514
                            4r2301
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   515
                            4r3012
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   516
                        ])
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   517
            colorMap:(Array with:(Color black)
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   518
                            with:(Color red)
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   519
                            with:(Color green)
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   520
                            with:(Color blue));
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   521
            magnifiedBy:30
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   522
        ) edit
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   523
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   524
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   525
      depth8 image with 3/3/2 rgb interpretation:
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   526
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   527
        ((Depth8Image
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   528
             width:16
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   529
             height:16
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   530
             fromArray:(ByteArray withAll:(0 to:16rFF)))
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   531
            photometric:#rgb;
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   532
            samplesPerPixel:3;
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   533
            bitsPerSample:#(3 3 2);
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   534
            magnifiedBy:10
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   535
        ) edit
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   536
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   537
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   538
      depth8 image with 2/2/2 rgb interpretation:
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   539
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   540
        ((Depth8Image
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   541
             width:8
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   542
             height:8
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   543
             fromArray:(ByteArray withAll:(0 to:16r3F)))
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   544
            photometric:#rgb;
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   545
            samplesPerPixel:3;
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   546
            bitsPerSample:#(2 2 2);
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   547
            magnifiedBy:10
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   548
        ) edit
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   549
                                                                        [exEnd]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   550
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   551
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   552
        ((Depth8Image
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   553
             width:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   554
             height:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   555
             fromArray:#[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   556
                    16r30 16r0C  16r03 16r3F
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   557
                    16r20 16r08  16r02 16r2A
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   558
                    16r10 16r04  16r01 16r15
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   559
                    16r00 16r00  16r00 16r00
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   560
                        ])
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   561
            photometric:#rgb;
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   562
            samplesPerPixel:3;
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   563
            bitsPerSample:#(2 2 2);
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   564
            magnifiedBy:30
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   565
        ) edit
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   566
                                                                        [exEnd]
5126
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   567
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   568
      trueColor image: remember: bytes are MSB
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   569
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   570
        ((Depth16Image
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   571
             width:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   572
             height:5
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   573
             fromArray:#[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   574
                    2r01111100 2r00000000  2r00000011 2r11100000  2r00000000 2r00011111  2r01111111 2r11111111
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   575
                    2r00111100 2r00000000  2r00000001 2r11100000  2r00000000 2r00001111  2r00111101 2r11101111
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   576
                    2r00011100 2r00000000  2r00000000 2r11100000  2r00000000 2r00000111  2r00011100 2r11100111
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   577
                    2r00001100 2r00000000  2r00000000 2r01100000  2r00000000 2r00000001  2r00001100 2r01100011
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   578
                    2r00000100 2r00000000  2r00000000 2r00100000  2r00000000 2r00000001  2r00000100 2r00100001
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   579
                        ])
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   580
            photometric:#rgb;
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   581
            samplesPerPixel:3;
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   582
            bitsPerSample:#(5 5 5);
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   583
            magnifiedBy:30
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   584
        ) edit
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   585
                                                                        [exEnd]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   586
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   587
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   588
        ((Depth24Image
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   589
             width:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   590
             height:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   591
             fromArray:#[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   592
                    16rFF 16r00 16r00  16rFF 16r00 16r00  16rFF 16r00 16r00  16rFF 16r00 16r00
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   593
                    16r00 16rFF 16r00  16r00 16rFF 16r00  16r00 16rFF 16r00  16r00 16rFF 16r00
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   594
                    16r00 16r00 16rFF  16r00 16r00 16rFF  16r00 16r00 16rFF  16r00 16r00 16rFF
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   595
                    16rFF 16rFF 16rFF  16rFF 16rFF 16rFF  16rFF 16rFF 16rFF  16rFF 16rFF 16rFF
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   596
                        ])
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   597
            photometric:#rgb;
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   598
            samplesPerPixel:3;
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   599
            bitsPerSample:#(8 8 8);
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   600
            magnifiedBy:30
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   601
        ) edit
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   602
                                                                        [exEnd]
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   603
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   604
      32bit trueColor image:
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   605
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   606
        ((Depth32Image
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   607
             width:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   608
             height:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   609
             fromArray:#[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   610
                    16rFF 16r00 16r00 16r00  16rFF 16r00 16r00 16r00  16rFF 16r00 16r00 16r00  16rFF 16r00 16r00 16r00
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   611
                    16r00 16rFF 16r00 16r00  16r00 16rFF 16r00 16r00  16r00 16rFF 16r00 16r00  16r00 16rFF 16r00 16r00
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   612
                    16r00 16r00 16rFF 16r00  16r00 16r00 16rFF 16r00  16r00 16r00 16rFF 16r00  16r00 16r00 16rFF 16r00
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   613
                    16rFF 16rFF 16rFF 16r00  16rFF 16rFF 16rFF 16r00  16rFF 16rFF 16rFF 16r00  16rFF 16rFF 16rFF 16r00
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   614
                        ])
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   615
            photometric:#rgb;
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   616
            samplesPerPixel:4;
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   617
            bitsPerSample:#(8 8 8 8);
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   618
            magnifiedBy:30
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   619
        ) edit
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   620
                                                                        [exEnd]
2760
94d2d524081b example added (24-bit image)
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   621
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   622
    storing - only a subset of formats (TIFF, XBM, XPM) currently support storing:
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   623
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   624
        |img|
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   625
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   626
        img := Image fromFile:'bitmaps/winBitmaps/okSmily_up.bmp' inPackage:'stx:goodies'.
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   627
        img saveOn:'myImage.tiff'.
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   628
        (Image fromFile:'myImage.tiff') inspect.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   629
        img saveOn:'myImage.gif'.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   630
        (Image fromFile:'myImage.gif') inspect.
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   631
                                                                        [exEnd]
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   632
649
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   633
    magnifying (any factor):
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   634
                                                                        [exBegin]
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   635
        ((Image fromFile:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies')
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   636
            magnifiedTo:(48@48))
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   637
                inspect
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   638
                                                                        [exEnd]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   639
                                                                        [exBegin]
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   640
        ((Image fromFile:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies')
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   641
            magnifiedBy:0.7)
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   642
                inspect
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   643
                                                                        [exEnd]
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   644
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   645
    rotating (any angle in degrees clockwise):
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   646
                                                                        [exBegin]
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   647
        ((Image fromFile:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies')
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   648
            rotated:90)
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   649
                inspect
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   650
                                                                        [exEnd]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   651
                                                                        [exBegin]
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   652
        (((Image fromFile:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies')
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   653
            magnifiedBy:0.3@0.7) rotated:270)
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   654
                inspect
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   655
                                                                        [exEnd]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   656
                                                                        [exBegin]
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   657
        (((Image fromFile:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies')
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   658
            ) rotated:30)
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   659
                inspect
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   660
                                                                        [exEnd]
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   661
    negative:
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   662
                                                                        [exBegin]
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   663
        ((Image fromFile:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies')
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   664
            negative)
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   665
                inspect
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   666
                                                                        [exEnd]
7123
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   667
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   668
      depth32 image with 8+8+8+8 argb interpretation:
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   669
                                                                        [exBegin]
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   670
        ((Depth32Image
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   671
             width:4 height:4
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   672
             fromArray:#[ 
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   673
                255 255 0 0       255 255 0 0       255 255 0 0       255 255 0 0
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   674
                255 0 255 0       255 0 255 0       255 0 255 0       255 0 255 0
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   675
                255 0 0 255       255 0 0 255       255 0 0 255       255 0 0 255
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   676
                255 255 255 255   255 255 255 255   255 255 255 255   255 255 255 255 ])
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   677
            photometric:#argb;
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   678
            samplesPerPixel:4;
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   679
            bitsPerSample:#(8 8 8 8);
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   680
            magnifiedBy:10
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   681
        ) edit
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   682
                                                                        [exEnd]
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   683
7126
a81b992fd069 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7123
diff changeset
   684
      depth32 image with 8+8+8+8 rgba interpretation:
a81b992fd069 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7123
diff changeset
   685
                                                                        [exBegin]
a81b992fd069 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7123
diff changeset
   686
        ((Depth32Image
a81b992fd069 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7123
diff changeset
   687
             width:4 height:4
a81b992fd069 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7123
diff changeset
   688
             fromArray:#[ 
a81b992fd069 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7123
diff changeset
   689
                255 0 0 255       255 0 0 255       255 0 0 255       255 0 0 255
a81b992fd069 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7123
diff changeset
   690
                0 255 0 255       0 255 0 255       0 255 0 255       0 255 0 255
a81b992fd069 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7123
diff changeset
   691
                0 0 255 255       0 0 255 255       0 0 255 255       0 0 255 255
a81b992fd069 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7123
diff changeset
   692
                255 255 255 255   255 255 255 255   255 255 255 255   255 255 255 255 ])
a81b992fd069 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7123
diff changeset
   693
            photometric:#rgba;
a81b992fd069 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7123
diff changeset
   694
            samplesPerPixel:4;
a81b992fd069 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7123
diff changeset
   695
            bitsPerSample:#(8 8 8 8);
a81b992fd069 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7123
diff changeset
   696
            magnifiedBy:10
a81b992fd069 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7123
diff changeset
   697
        ) edit
a81b992fd069 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7123
diff changeset
   698
                                                                        [exEnd]
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   699
"
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   700
!
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   701
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   702
examples_functionalImages
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   703
"
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   704
    Functional images (please read 'Functional Images' by Conal Elliot, Microsoft Research).
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
   705
    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
   706
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   707
    Plain x/y mapping:
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   708
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   709
        |i|
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   710
        i := Depth1Image extent:256@256.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   711
        i pixelFunction:[:x :y | ((x // 16) bitXor:(y // 16)) odd ifTrue:1 ifFalse:[0]].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   712
        i inspect.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   713
                                                                        [exEnd]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   714
    Transformed x/y mapping:
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   715
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   716
        |i f|
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   717
        f := [:x :y | (x between:0.4 and:0.6) asInteger].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   718
        i := Depth1Image extent:256@256.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   719
        i pixelFunction:f inX:(0.0 to:1.0) y:(0.0 to:1.0).
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   720
        i inspect.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   721
                                                                        [exEnd]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   722
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   723
        |i f|
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   724
        f := [:x :y | ((x between:0.4 and:0.6) or:[(y between:0.4 and:0.6)]) asInteger].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   725
        i := Depth1Image extent:256@256.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   726
        i pixelFunction:f inX:(0.0 to:1.0) y:(0.0 to:1.0).
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   727
        i inspect.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   728
                                                                        [exEnd]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   729
    Image based on polar coordinate:
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   730
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   731
        |i f|
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   732
        f := [:x :y | ((x@y) r * 10) asInteger bitAnd:1].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   733
        i := Depth1Image extent:256@256.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   734
        i pixelFunction:f inX:(-1.0 to:1.0) y:(-1.0 to:1.0).
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   735
        i inspect.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   736
                                                                        [exEnd]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   737
    Grayscale image based on polar coordinate:
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   738
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   739
        |i|
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   740
        i := Depth8Image extent:256@256.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   741
        i photometric:#blackIs0.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   742
        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
   743
        i inspect.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   744
                                                                        [exEnd]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   745
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   746
    Taking another image as ''input''
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   747
                                                                        [exBegin]
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   748
        |garfield f i h|
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   749
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   750
        garfield := Image fromFile:'bitmaps/gifImages/garfield.gif' inPackage:'stx:goodies'.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   751
        h := garfield height.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   752
        f := [:x :y | (garfield colorAtX:x y:h-y) rgbValue].
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   753
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   754
        i := Depth24Image extent:garfield extent.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   755
        i pixelFunction:f.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   756
        i inspect.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   757
                                                                        [exEnd]
649
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   758
"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   759
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
   760
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   761
!Image class methodsFor:'initialization'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   762
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   763
addReader:aReaderClass suffix:aSuffix
5216
f7ec910cfce1 Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 5200
diff changeset
   764
    <resource: #obsolete>
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   765
    "register an additional image reader.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   766
     This is provided for subclasses, to regster themself when
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   767
     loaded (or from the startup scripts)"
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   768
1800
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   769
    self obsoleteMethodWarning.
1780
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   770
    self addReader:aReaderClass suffix:aSuffix mimeType:nil
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   771
!
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   772
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   773
addReader:aReaderClass suffix:aSuffix mimeType:mimeType
5216
f7ec910cfce1 Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 5200
diff changeset
   774
    <resource: #obsolete>
1780
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   775
    "register an additional image reader.
1800
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   776
     This interface is kept for backward compatibility.
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   777
     The knowledge has been concentrated in MIMETypes"
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   778
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   779
    self obsoleteMethodWarning.
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   780
    MIMETypes
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   781
	defineImageType:mimeType suffix:aSuffix reader:aReaderClass
1780
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   782
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   783
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   784
     Image addReader:GIFReader suffix:'gif'
1780
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   785
     Image addReader:GIFReader suffix:'gif' mimeType:'image/gif'
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   786
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   787
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   788
    "Modified: 30.6.1997 / 21:59:59 / cg"
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   789
!
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   790
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   791
fileFormats
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   792
    "return the collection of supported file formats.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   793
     The returned dictionary maps file-extensions to image reader classes."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   794
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   795
    ^ MIMETypes fileSuffixToImageReaderMapping
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   796
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   797
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   798
     Image fileFormats
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
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   801
    "Modified: 30.6.1997 / 22:05:58 / cg"
100
1b0b86c77397 co !!:*
claus
parents: 89
diff changeset
   802
!
1b0b86c77397 co !!:*
claus
parents: 89
diff changeset
   803
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   804
flushDeviceImages
869
464ffa8c0c67 comment
Claus Gittinger <cg@exept.de>
parents: 861
diff changeset
   805
    "simply release all deviceForms"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   806
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   807
    Lobby do:[:anImage |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   808
	anImage release
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   809
    ]
869
464ffa8c0c67 comment
Claus Gittinger <cg@exept.de>
parents: 861
diff changeset
   810
464ffa8c0c67 comment
Claus Gittinger <cg@exept.de>
parents: 861
diff changeset
   811
    "Modified: 15.6.1996 / 15:45:02 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   812
!
48194c26a46c Initial revision
claus
parents:
diff changeset
   813
48194c26a46c Initial revision
claus
parents:
diff changeset
   814
initialize
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
   815
    "initialize class constants"
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
   816
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   817
    "setup tracker of known pictures"
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   818
    Lobby isNil ifTrue:[
7170
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   819
        Lobby := Registry new.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   820
        ObjectMemory addDependent:self.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   821
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   822
        "/ define the algorithm to use for dithering -
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   823
        "/ supported values are:
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   824
        "/      #threshold
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   825
        "/      #ordered
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   826
        "/      #floydSteinberg
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   827
        "/      #burkes
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   828
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   829
        DitherAlgorithm := #floydSteinberg.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   830
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   831
        (Display notNil and:[Display hasGrayscales]) ifFalse:[
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   832
            NumberOfDitherColors := 64
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   833
        ] ifTrue:[
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   834
            "as far as I remember, this is about the number of grey values, the eye can distinguish"
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   835
            NumberOfDitherColors := 100
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   836
        ].
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   837
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   838
        "define reader classes"
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   839
        self initializeFileFormatTable.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   840
        self initializeMIMETable.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   841
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   842
        CollectGarbageWhenRunningOutOfColors := false.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   843
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   844
        ImageErrorSignal := Error newSignalMayProceed:true.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   845
        ImageErrorSignal nameClass:self message:#imageErrorSignal.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   846
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   847
        ImageSaveErrorSignal := ImageErrorSignal newSignalMayProceed:true.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   848
        ImageSaveErrorSignal nameClass:self message:#imageSaveErrorSignal.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   849
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   850
        FileCreationErrorSignal := ImageSaveErrorSignal newSignalMayProceed:true.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   851
        FileCreationErrorSignal nameClass:self message:#fileCreationErrorSignal.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   852
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   853
        CannotRepresentImageSignal := ImageSaveErrorSignal newSignalMayProceed:true.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   854
        CannotRepresentImageSignal nameClass:self message:#cannotRepresentImageSignal.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   855
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   856
        ImageLoadErrorSignal := QuerySignal new.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   857
        ImageLoadErrorSignal nameClass:self message:#imageLoadErrorSignal.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   858
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   859
        ImageNotFoundQuerySignal := QuerySignal new.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   860
        ImageNotFoundQuerySignal nameClass:self message:#imageNotFoundQuerySignal.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   861
        ImageNotFoundQuerySignal parent:ImageLoadErrorSignal.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   862
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   863
        InformationLostQuerySignal := QuerySignal new.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   864
        InformationLostQuerySignal nameClass:self message:#informationLostQuerySignal.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   865
        InformationLostQuerySignal parent:ImageLoadErrorSignal.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   866
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   867
        BadImageFormatQuerySignal := QuerySignal new.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   868
        BadImageFormatQuerySignal nameClass:self message:#badImageFormatQuerySignal.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   869
        BadImageFormatQuerySignal parent:ImageLoadErrorSignal.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   870
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   871
        UnrepresentableColorSignal := ImageErrorSignal newSignalMayProceed:true.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   872
        UnrepresentableColorSignal nameClass:self message:#unrepresentableColorSignal.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   873
    ].
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   874
    UninterpretedBytes isBigEndian ifTrue:[
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   875
        ARGB_A_OFFSET_MACHINE := 1.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   876
        ARGB_R_OFFSET_MACHINE := 2.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   877
        ARGB_G_OFFSET_MACHINE := 3.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   878
        ARGB_B_OFFSET_MACHINE := 4.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   879
    ] ifFalse:[ 
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   880
        ARGB_A_OFFSET_MACHINE := 4.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   881
        ARGB_R_OFFSET_MACHINE := 3.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   882
        ARGB_G_OFFSET_MACHINE := 2.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   883
        ARGB_B_OFFSET_MACHINE := 1.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   884
    ].
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   885
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   886
    "Modified: / 18-05-1999 / 15:50:03 / cg"
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   887
    "Modified: / 28-02-2016 / 14:36:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   888
!
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   889
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   890
initializeFileFormatTable
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   891
    "initialize a default table to map from file extension to reader class.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   892
     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
   893
     see the 'smalltalk.rc'/'display.rc' startup files for a real (full) map."
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   894
1814
5d413419cf51 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1802
diff changeset
   895
    MIMETypes notNil ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   896
	MIMETypes imageReaderForSuffix:'xbm'  put:XBMReader.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   897
	MIMETypes imageReaderForSuffix:'tiff' put:TIFFReader.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   898
	MIMETypes imageReaderForSuffix:'gif'  put:GIFReader.
1814
5d413419cf51 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1802
diff changeset
   899
    ].
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   900
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   901
    "
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   902
     Image initializeFileFormatTable
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   903
    "
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   904
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   905
    "Modified: 30.6.1997 / 22:07:28 / cg"
1785
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   906
!
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   907
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   908
initializeMIMETable
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   909
    "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
   910
     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
   911
     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
   912
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   913
    MIMETypes notNil ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   914
	MIMETypes mimeTypeForSuffix:'gif'       put:'image/gif'.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   915
	MIMETypes mimeTypeForSuffix:'tiff'      put:'image/tiff'.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   916
	MIMETypes mimeTypeForSuffix:'tif'       put:'image/tiff'.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   917
	MIMETypes mimeTypeForSuffix:'xbm'       put:'image/x-xbitmap'.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   918
	MIMETypes mimeTypeForSuffix:'xpm'       put:'image/x-xpixmap'.
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   919
    ].
1785
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   920
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   921
    "
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   922
     Image initializeMIMETable
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   923
    "
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   924
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   925
    "Created: 27.6.1997 / 16:43:48 / cg"
1815
50212910fc13 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   926
    "Modified: 21.7.1997 / 17:33:59 / cg"
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   927
!
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   928
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
   929
update:something with:aParameter from:changedObject
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   930
    "flush all device specific stuff when restarted from a snapshot"
48194c26a46c Initial revision
claus
parents:
diff changeset
   931
48194c26a46c Initial revision
claus
parents:
diff changeset
   932
    (something == #restarted) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   933
	self flushDeviceImages
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   934
    ]
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
   935
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
   936
    "Created: 21.6.1996 / 19:47:43 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   937
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
   938
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   939
!Image class methodsFor:'instance creation'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   940
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   941
extent:ext
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   942
    "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
   943
     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
   944
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   945
    ^ 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
   946
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   947
    "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
   948
    "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
   949
!
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   950
3023
cb063801decd more Squeak compatibility
ps
parents: 2980
diff changeset
   951
extent:ext depth:d
cb063801decd more Squeak compatibility
ps
parents: 2980
diff changeset
   952
    "ST-80 compatibility"
cb063801decd more Squeak compatibility
ps
parents: 2980
diff changeset
   953
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   954
    ^ self width:ext x height:ext y depth:d
3023
cb063801decd more Squeak compatibility
ps
parents: 2980
diff changeset
   955
!
cb063801decd more Squeak compatibility
ps
parents: 2980
diff changeset
   956
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   957
extent:ext depth:d antiAliasedPalette:aBasicColorArray bgColor:bgColor
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   958
    ^ 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
   959
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   960
    "
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   961
	|colorMap aaImgArray|
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   962
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   963
	colorMap := Array with:Color white with:Color blue.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   964
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   965
	aaImgArray := Depth8Image extent:300@400 depth:8 antiAliasedPalette:colorMap bgColor:Color white.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   966
	aaImgArray last
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   967
	    fillAntiAliasedArc:200@200
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   968
	    radius:80
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   969
	    from:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   970
	    angle:360
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   971
	    withColor:Color blue
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   972
	    antiAliasedPalette:aaImgArray first
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   973
	    startWith:aaImgArray second.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   974
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   975
	aaImgArray last inspect.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   976
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   977
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   978
	|colorMap aaImgArray|
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   979
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   980
	colorMap := Array with:Color white with:Color black with:Color red with:Color blue.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   981
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   982
	aaImgArray := Depth8Image extent:300@400 depth:8 antiAliasedPalette:colorMap bgColor:Color white.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   983
	aaImgArray last fillAntiAliasedArc:205@195 radius:80 from:0 angle:90 withColor:Color red
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   984
	    colorDictionary:aaImgArray first
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   985
	    blendStart:aaImgArray second.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   986
	aaImgArray last fillAntiAliasedArc:200@200 radius:80 from:90 angle:270 withColor:Color blue
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   987
	    colorDictionary:aaImgArray first
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   988
	    blendStart:aaImgArray second.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   989
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   990
	aaImgArray last inspect.
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   991
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   992
    "
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   993
!
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   994
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   995
extent:ext depth:d antiAliasedPalette:aBasicColorArray bgColor:bgColor mixedArray:mixedArray
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   996
    |colors colorMap colorIndex colorDictionary tmpDic newImage emptyBits|
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   997
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   998
    colors := OrderedCollection new.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   999
    colorMap := OrderedCollection new.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1000
    colorIndex := 0.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1001
    colorDictionary := Dictionary new.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1002
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1003
    aBasicColorArray do:[:aColor |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1004
	colorMap add:aColor.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1005
	colorIndex := colorIndex + 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1006
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1007
	tmpDic := Dictionary new.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1008
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1009
	mixedArray do:[:aFloat |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1010
	    tmpDic at:aFloat put:colorIndex.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1011
	    colorMap add:(aColor mixed:aFloat with:bgColor).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1012
	    colorIndex := colorIndex + 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1013
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1014
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1015
	colorDictionary at:aColor put:tmpDic.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1016
    ].
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1017
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1018
    newImage := (self implementorForDepth:d) new.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1019
    newImage width:ext x height:ext y depth:d palette:colorMap.
5643
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1020
    newImage createPixelStore.
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1021
"/    emptyBits := ByteArray new:(newImage bytesPerRow * ext y).
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1022
"/    newImage bits:emptyBits.
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1023
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  1024
    ^ Array with:colorDictionary with:mixedArray first with:newImage
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  1025
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  1026
    "
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1027
	|colorMap aaImgArray|
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1028
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1029
	colorMap := Array with:Color white with:Color black with:Color red with:Color blue.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1030
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1031
	aaImgArray := Depth8Image extent:300@400 depth:8 antiAliasedPalette:colorMap bgColor:Color white.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1032
	aaImgArray last fillAntiAliasedArc:205@195 radius:80 from:0 angle:90 withColor:Color red
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1033
	    colorDictionary:aaImgArray first
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1034
	    blendStart:aaImgArray second.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1035
	aaImgArray last fillAntiAliasedArc:200@200 radius:80 from:90 angle:270 withColor:Color blue
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1036
	    colorDictionary:aaImgArray first
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1037
	    blendStart:aaImgArray second.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1038
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1039
	aaImgArray last inspect.
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  1040
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  1041
 ###################
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  1042
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1043
	|colorMap aaImgArray|
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1044
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1045
	colorMap := Array with:Color white with:Color blue.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1046
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1047
	aaImgArray := Depth8Image extent:300@400 depth:8 antiAliasedPalette:colorMap bgColor:Color white.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1048
	aaImgArray last
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1049
	    fillAntiAliasedArc:200@200
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1050
	    radius:80
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1051
	    from:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1052
	    angle:360
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1053
	    withColor:Color blue
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1054
	    antiAliasedPalette:aaImgArray first
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1055
	    startWith:aaImgArray second.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1056
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1057
	aaImgArray last inspect.
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1058
    "
5643
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1059
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1060
    "Modified: / 02-11-2010 / 20:57:41 / cg"
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1061
!
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1062
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1063
extent:ext depth:d bits:bits
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1064
    "ST-80 compatibility; assume 32-bit padding"
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 extent:ext depth:d bits:bits pad:32
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
  1067
!
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
  1068
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1069
extent:ext depth:d bits:bits pad:padding
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1070
    "ST-80 compatibility"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1071
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1072
    ^ self width:ext x height:ext y depth:d fromArray:bits pad:padding
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
  1073
!
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
  1074
1276
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1075
extent:ext depth:d bitsPerPixel:bpp palette:aColormap usingBits:bits
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1076
    "ST-80 compatibility"
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
    |img|
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1079
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1080
    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
  1081
    img colorMap:aColormap.
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1082
    ^ img
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1083
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1084
    "Created: 25.1.1997 / 03:50:22 / cg"
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1085
    "Modified: 25.1.1997 / 12:27:35 / cg"
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1086
!
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1087
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1088
extent:ext depth:d palette:aColormap
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1089
    "create & return a blank image of the given size.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1090
     ST-80 compatibility"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1091
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1092
    |newImage emptyBits|
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1093
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1094
    newImage := (self implementorForDepth:d) new.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1095
    newImage width:ext x height:ext y depth:d palette:aColormap.
5643
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1096
    newImage createPixelStore.
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1097
"/    emptyBits := ByteArray new:(newImage bytesPerRow * ext y).
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1098
"/    newImage bits:emptyBits.
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1099
    ^ newImage
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1100
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1101
    "
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1102
     Image extent:16@16 depth:8 palette:nil
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1103
     Image extent:16@16 depth:4 palette:nil
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1104
     Image extent:16@16 depth:2 palette:nil
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1105
    "
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1106
5643
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1107
    "Created: / 06-03-1997 / 15:24:01 / cg"
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1108
    "Modified: / 02-11-2010 / 20:56:53 / cg"
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1109
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1110
1070
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1111
extent:ext depth:d palette:aColormap bits:bits
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1112
    "ST-80 compatibility"
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1113
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1114
    ^ self extent:ext depth:d palette:aColormap bits:bits pad:16
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1115
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1116
    "Modified: 7.10.1996 / 11:32:16 / cg"
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1117
!
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1118
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1119
extent:ext depth:d palette:aColormap bits:bits pad:padding
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1120
    "ST-80 compatibility"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1121
1070
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1122
    |img|
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1123
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1124
    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
  1125
    img colorMap:aColormap.
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1126
    ^ img
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1127
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1128
    "Modified: 7.10.1996 / 11:32:00 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1129
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1130
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1131
extent:ext fromArray:bits offset:offset
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1132
    "ST-80 compatibility"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1133
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1134
    ^ self width:ext x height:ext y fromArray:bits
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1135
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1136
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1137
fromForm:aForm
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1138
    "create & return an Image given a aForm"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1139
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1140
    ^ self fromSubForm:(0@0 extent:aForm extent) in:aForm
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1141
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1142
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1143
     |f|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1144
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1145
     f := Form width:16 height:16.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1146
     f clear.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1147
     f displayLineFromX:0 y:0 toX:15 y:15.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1148
     f inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1149
     (Image fromForm:f) inspect
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1150
    "
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1151
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1152
    "
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1153
     |f|
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1154
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1155
     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
  1156
     f clear.
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1157
     f paint:(Color red).
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1158
     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
  1159
     f paint:(Color green).
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1160
     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
  1161
     f inspect.
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1162
     (Image fromForm:f) inspect
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1163
    "
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1164
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
  1165
    "Modified: 11.7.1996 / 11:21:42 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1166
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1167
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1168
fromImage:anImage
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1169
    "create & return an Image given another image. This can be used to
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1170
     convert an image to another depth."
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1171
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1172
    ^ 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
  1173
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1174
    "
3448
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1175
     |i i2 idx|
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1176
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1177
     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
  1178
     i2 := i deepCopy.
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1179
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1180
     idx := i2 colorMap indexOfPaintNearest:(Color green).
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1181
     i2 colorMap at:idx put:Color red.
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1182
     i2 inspect.
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1183
     i inspect.
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1184
    "
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1185
!
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1186
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1187
fromImage:anImage photometric:photometricOrNil
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1188
    "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
  1189
     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
  1190
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1191
    (self == Image
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1192
    or:[anImage class == self
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  1193
	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
  1194
    ^ self new fromImage:anImage photometric:photometricOrNil.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1195
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1196
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1197
     |i1 i8|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1198
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  1199
     i1 := Image fromFile:'goodies/bitmaps/SBrowser.xbm'.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1200
     i8 := Depth8Image fromImage:i1.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1201
     i8 inspect
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1202
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1203
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1204
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1205
fromSubForm:aRectangle in:aForm
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1206
    "create & return an subImage given a aForm"
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1207
4937
1b0ebaed9336 photometric fix
Claus Gittinger <cg@exept.de>
parents: 4893
diff changeset
  1208
    |depth device vis img photometric|
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1209
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1210
    depth := aForm depth.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1211
    device := aForm device.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1212
4937
1b0ebaed9336 photometric fix
Claus Gittinger <cg@exept.de>
parents: 4893
diff changeset
  1213
    photometric := (depth > 8) ifTrue:#rgb ifFalse:#palette.
1b0ebaed9336 photometric fix
Claus Gittinger <cg@exept.de>
parents: 4893
diff changeset
  1214
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1215
    (device notNil and:[depth == device depth]) ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1216
	"/
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1217
	"/ for truecolor displays, return a Depth24Image
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1218
	"/ (must do this for depth15 & depth16 displays, since
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1219
	"/  Depth16Image has no way to specify r/g/b masks ...)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1220
	"/
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1221
	vis := device visualType.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1222
	(vis == #TrueColor or:[vis == #DirectColor]) ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1223
	    depth > 8 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1224
		depth := 24.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1225
	    ]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1226
	].
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1227
    ].
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1228
    img := self newForDepth:depth.
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1229
    img photometric:photometric.
4937
1b0ebaed9336 photometric fix
Claus Gittinger <cg@exept.de>
parents: 4893
diff changeset
  1230
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1231
    device isNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1232
	^ img from:aForm in:aRectangle.
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1233
    ].
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1234
    ^ img from:aForm in:aRectangle
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1235
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1236
    "
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1237
     |f|
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1238
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1239
     f := Form width:16 height:16.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1240
     f clear.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1241
     f displayLineFromX:0 y:0 toX:15 y:15.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1242
     f inspect.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1243
     (Image fromForm:f) inspect.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1244
     (Image fromSubForm:(5@5 corner:10@10) in:f) inspect
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1245
    "
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1246
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1247
    "
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1248
     |f|
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1249
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1250
     f := Form width:16 height:16 depth:(Display depth) on:Display.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1251
     f clear.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1252
     f paint:(Color red).
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1253
     f displayLineFromX:0 y:0 toX:15 y:15.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1254
     f paint:(Color green).
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1255
     f displayLineFromX:15 y:0 toX:0 y:15.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1256
     f inspect.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1257
     (Image fromForm:f) inspect.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1258
     (Image fromSubForm:(5@5 corner:10@10) in:f) inspect
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1259
    "
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1260
!
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1261
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1262
fromSubImage:anImage in:aRectangle
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1263
    "create & return an Image from a rectangular area in another image.
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1264
     This can also be used to get a subimage in another depth.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1265
     As with layouts, the rectangle may contain integers (= nr of pixels) or float numbers (= relative size).
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1266
     Color precision may be lost, if conversion is from a higher depth image. 
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1267
     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
  1268
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1269
    |cls|
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1270
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1271
    self == Image ifTrue:[
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1272
        cls := (self implementorForDepth:anImage depth).
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1273
    ] ifFalse:[
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1274
        cls := self.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1275
    ].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1276
    ^ cls new fromSubImage:anImage in:aRectangle.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1277
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1278
    "
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1279
     |i1 i8|
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1280
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1281
     i1 := Image fromFile:'bitmaps/gifImages/garfield.gif' inPackage:'stx:goodies'.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1282
     i8 := Depth8Image fromSubImage:i1 in:(250@90 extent:50@50).
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1283
     i8 inspect
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1284
    "
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1285
    "
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1286
     |i1 i8|
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1287
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1288
     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
  1289
     i8 := Image fromSubImage:i1 in:(70@50 extent:50@50).
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1290
     i8 inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1291
    "
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1292
    "
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1293
     |i1 i24|
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1294
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1295
     i1 := Image fromFile:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies'.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1296
     i24 := Depth24Image fromSubImage:i1 in:(70@50 extent:50@50).
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1297
     i24 inspect
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1298
    "
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1299
    "
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1300
     |i1 i24|
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1301
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1302
     i1 := Image fromFile:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies'.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1303
     i1 inspect.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1304
     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
  1305
     i24 inspect
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1306
    "
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1307
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1308
    "Created: 20.9.1995 / 01:05:43 / claus"
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  1309
    "Modified: 24.4.1997 / 23:13:02 / cg"
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1310
!
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1311
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1312
new
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1313
    "create a new image. Redefined to set the photometric to
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1314
     greyScale with black being 0 as default."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1315
4416
fb209558d622 proper #initialize
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
  1316
    ^ self basicNew initialize
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1317
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1318
    "Modified: 10.6.1996 / 18:08:37 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1319
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1320
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1321
newForDepth:depth
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1322
    "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
  1323
     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
  1324
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1325
    |cls|
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1326
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1327
    cls := self implementorForDepth:depth.
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1328
    ^ cls new
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1329
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1330
    "
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1331
     Image newForDepth:8
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1332
    "
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1333
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1334
    "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
  1335
!
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1336
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1337
width:w height:h
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1338
    "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
  1339
     Assume a depth of 1, unless an explicit imageClass is the receiver."
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1340
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1341
    |cls|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1342
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1343
    cls := self.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1344
    cls == Image ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1345
	cls := self implementorForDepth:1
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  1346
    ].
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  1347
    ^ cls new width:w height:h
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  1348
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  1349
    "Modified: / 06-06-2007 / 11:10:55 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1350
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1351
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1352
width:w height:h depth:d
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1353
    "create a new image, given width, height and depth"
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1354
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1355
    ^ (self newForDepth:d)
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1356
	width:w height:h depth:d
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1357
!
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1358
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1359
width:w height:h depth:d fromArray:pixelData
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1360
    "create a new image, given width, height, depth and data.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1361
     Data must be a ByteArray containing correctly aligned bits for the specified
134
claus
parents: 132
diff changeset
  1362
     depth (8-bit padded)."
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1363
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1364
    ^ (self newForDepth:d)
7101
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1365
        width:w height:h depth:d fromArray:pixelData
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1366
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1367
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1368
     Image width:8
7101
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1369
           height:8
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1370
           depth:1
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1371
           fromArray:#[2r11001100
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1372
                       2r00110011
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1373
                       2r11001100
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1374
                       2r00110011
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1375
                       2r11001100
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1376
                       2r00110011
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1377
                       2r11001100
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1378
                       2r00110011].
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1379
    "
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1380
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1381
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1382
     Image width:8
7101
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1383
           height:8
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1384
           depth:2
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1385
           fromArray:#[4r1100 4r1100
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1386
                       4r0011 4r0011
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1387
                       4r1100 4r1100
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1388
                       4r0011 4r0011
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1389
                       4r1100 4r1100
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1390
                       4r0011 4r0011
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1391
                       4r1100 4r1100
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1392
                       4r0011 4r0011].
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1393
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1394
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1395
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1396
     Image width:8
7101
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1397
           height:8
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1398
           depth:4
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1399
           fromArray:#[16r00 16r01 16rf0 16rf1
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1400
                       16r02 16r03 16rf2 16rf3
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1401
                       16r04 16r05 16rf4 16rf5
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1402
                       16r06 16r07 16rf6 16rf7
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1403
                       16r08 16r09 16rf8 16rf9
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1404
                       16r0a 16r0b 16rfa 16rfb
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1405
                       16r0c 16r0d 16rfc 16rfd
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1406
                       16r0e 16r0f 16rfe 16rff].
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1407
    "
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1408
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1409
    "
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1410
     Image width:8
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1411
           height:8
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1412
           depth:16
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1413
           fromArray:#(1 1 1 1 1 1 1 1
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1414
                       2 2 2 2 2 2 2 2    
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1415
                       3 3 3 3 3 3 3 3    
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1416
                       4 4 4 4 4 4 4 4    
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1417
                       5 5 5 5 5 5 5 5    
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1418
                       6 6 6 6 6 6 6 6    
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1419
                       7 7 7 7 7 7 7 7    
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1420
                       8 8 8 8 8 8 8 8    
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1421
                      ) asWordArray.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1422
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1423
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1424
    "Modified: 10.6.1996 / 18:18:10 / cg"
132
claus
parents: 125
diff changeset
  1425
!
claus
parents: 125
diff changeset
  1426
134
claus
parents: 132
diff changeset
  1427
width:w height:h depth:d fromArray:pixelData pad:padding
claus
parents: 132
diff changeset
  1428
    "create a new image, given width, height, depth and data.
claus
parents: 132
diff changeset
  1429
     Data must be a ByteArray containing correctly aligned bits for the specified
claus
parents: 132
diff changeset
  1430
     depth."
claus
parents: 132
diff changeset
  1431
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1432
    |img newBits
2772
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  1433
     srcRowBytes "{ Class: SmallInteger }"
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  1434
     dstRowBytes "{ Class: SmallInteger }"
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  1435
     nextDstIndex "{ Class: SmallInteger }"
2527
5391e6e2c8a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2526
diff changeset
  1436
     srcIndex "{ Class: SmallInteger }"
5391e6e2c8a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2526
diff changeset
  1437
     dstIndex "{ Class: SmallInteger }" |
134
claus
parents: 132
diff changeset
  1438
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1439
    img := (self newForDepth:d) width:w height:h depth:d .
134
claus
parents: 132
diff changeset
  1440
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1441
    srcRowBytes := ((w * d + padding - 1) bitShift:-5) bitShift:2.
5341
ede63c3764ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5326
diff changeset
  1442
    dstRowBytes := img bytesPerRow.
ede63c3764ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5326
diff changeset
  1443
ede63c3764ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5326
diff changeset
  1444
    (padding ~~ 8 and:[(srcRowBytes \\ 4 ~~ 0) or:[srcRowBytes ~= dstRowBytes]]) ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1445
	"must repad; ST/X uses byte padding, while ST-80 uses longword
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1446
	 padding. This is stupid, and may be changed in ST/X with future versions.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1447
	"
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1448
	dstRowBytes := img bytesPerRow.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1449
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1450
	newBits := ByteArray uninitializedNew:(dstRowBytes * h).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1451
	srcIndex := 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1452
	dstIndex := 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1453
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1454
	1 to:h do:[:row |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1455
	    nextDstIndex := dstIndex + dstRowBytes.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1456
	    newBits replaceFrom:dstIndex
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1457
			     to:(nextDstIndex - 1)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1458
			   with:pixelData
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1459
		     startingAt:srcIndex.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1460
	    srcIndex := srcIndex + srcRowBytes.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1461
	    dstIndex := nextDstIndex.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1462
	].
134
claus
parents: 132
diff changeset
  1463
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1464
	pixelData class isBytes ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1465
	    newBits := ByteArray withAll:pixelData
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1466
	] ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1467
	    newBits := pixelData
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1468
	]
134
claus
parents: 132
diff changeset
  1469
    ].
claus
parents: 132
diff changeset
  1470
    img bits:newBits.
claus
parents: 132
diff changeset
  1471
    ^ img
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1472
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1473
    "Modified: / 27-05-2007 / 14:01:32 / cg"
134
claus
parents: 132
diff changeset
  1474
!
claus
parents: 132
diff changeset
  1475
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1476
width:w height:h fromArray:anArray
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1477
    "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
  1478
     receiving class is Image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1479
     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
  1480
     (i.e. 8 bits per byte)."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1481
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1482
    |cls d pixels|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1483
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1484
    cls := self.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1485
    cls == Image ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1486
	cls := self implementorForDepth:1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1487
	d := 1.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1488
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1489
	d := cls imageDepth
283
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
    anArray class isBytes ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1492
	pixels := ByteArray withAll:anArray
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1493
    ] ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1494
	pixels := anArray
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1495
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1496
    ^ cls new width:w height:h depth:d fromArray:pixels
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1497
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1498
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1499
     Image width:8
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1500
	   height:8
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1501
	   fromArray:#[2r11001100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1502
		       2r00110011
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1503
		       2r11001100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1504
		       2r00110011
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1505
		       2r11001100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1506
		       2r00110011
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1507
		       2r11001100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1508
		       2r00110011].
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1509
    "
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1510
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1511
    "Modified: 8.6.1996 / 10:07:26 / cg"
6899
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1512
!
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1513
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1514
width:w height:h photometric:photometric
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1515
    "create a new image, given width, height.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1516
     Assume a depth of 1, unless an explicit imageClass is the receiver."
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1517
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1518
    |cls|
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1519
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1520
    cls := self.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1521
    cls == Image ifTrue:[
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1522
        cls := self implementorForDepth:1
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1523
    ].
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1524
    ^ cls new width:w height:h; photometric:photometric; yourself
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1525
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1526
    "Modified: / 06-06-2007 / 11:10:55 / cg"
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1527
!
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1528
6899
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1529
width:w height:h photometric:photometric bitsPerSample:bitsPerSample
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1530
    "create a new image, given width, height.
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1531
     Assume a depth of 1, unless an explicit imageClass is the receiver."
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1532
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1533
    |cls|
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1534
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1535
    cls := self.
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1536
    cls == Image ifTrue:[
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1537
        cls := self implementorForDepth:1
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1538
    ].
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1539
    ^ cls new width:w height:h; photometric:photometric; bitsPerSample:bitsPerSample; yourself
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1540
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1541
    "Modified: / 06-06-2007 / 11:10:55 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1542
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1543
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1544
!Image class methodsFor:'Signal constants'!
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1545
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1546
badImageFormatQuerySignal
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1547
    "return the (query-) signal, which is raised if some
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1548
     bitmap-image could not be loaded due to an unrecognized format.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1549
     If unhandled, the image-load returns nil.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1550
     Otherwise, it returns whatever the handler proceeds with.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1551
     The exception gets either the images fileName or an input stream
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1552
     as parameter"
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1553
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1554
    ^ BadImageFormatQuerySignal
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1555
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1556
    "Created: 1.2.1997 / 14:40:29 / cg"
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1557
!
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1558
1385
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1559
cannotRepresentImageSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1560
    "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
  1561
     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
  1562
     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
  1563
     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
  1564
     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
  1565
     (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
  1566
     format then."
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1567
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
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1570
    "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
  1571
!
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1572
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1573
fileCreationErrorSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1574
    "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
  1575
     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
  1576
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1577
    ^ FileCreationErrorSignal
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:32:59 / 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
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1582
imageErrorSignal
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1583
    "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
  1584
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1585
    ^ ImageErrorSignal
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1586
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1587
    "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
  1588
!
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1589
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1590
imageLoadErrorSignal
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1591
    "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
  1592
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1593
    ^ ImageLoadErrorSignal
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1594
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1595
    "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
  1596
!
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1597
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1598
imageNotFoundQuerySignal
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1599
    "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
  1600
     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
  1601
     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
  1602
     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
  1603
     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
  1604
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1605
    ^ ImageNotFoundQuerySignal
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1606
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1607
    "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
  1608
!
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1609
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1610
imageSaveErrorSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1611
    "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
  1612
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1613
    ^ ImageSaveErrorSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1614
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1615
    "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
  1616
!
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
informationLostQuerySignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1619
    "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
  1620
     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
  1621
     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
  1622
     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
  1623
     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
  1624
     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
  1625
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1626
    ^ InformationLostQuerySignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1627
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1628
    "Created: 27.2.1997 / 12:43:50 / cg"
2182
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1629
!
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1630
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1631
unrepresentableColorSignal
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1632
    "return the signal, which is raised if some color is not
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1633
     representable in the image (when storing a pixel)."
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1634
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1635
    ^ UnrepresentableColorSignal
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1636
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1637
    "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
  1638
! !
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1639
1230
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1640
!Image class methodsFor:'cleanup'!
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1641
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1642
releaseResourcesOnDevice:aDevice
1230
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1643
    "this is sent when a display connection is closed,
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1644
     to release all cached Images from that device"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1645
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1646
    Lobby
6390
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
  1647
        unregisterAllForWhich:[:eachImage |
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
  1648
            |ok|
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
  1649
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
  1650
            ok := eachImage graphicsDevice == aDevice.
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
  1651
            ok ifTrue:[
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
  1652
                eachImage releaseFromDevice
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
  1653
            ].
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
  1654
            ok
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
  1655
        ].
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
  1656
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
  1657
    "
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
  1658
      self releaseResourcesOnDevice:Screen current
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
  1659
    "
1230
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1660
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1661
    "Created: 16.1.1997 / 19:30:44 / cg"
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1662
    "Modified: 16.1.1997 / 19:33:49 / cg"
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1663
! !
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1664
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  1665
!Image class methodsFor:'file reading'!
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1666
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1667
fromFile:aFileName
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1668
    "read an image from a file - this methods tries to find
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1669
     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
  1670
     and lets the appropriate reader read the file.
6375
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1671
     Also, unless the path is absolute,
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1672
     all bitmap directories along the searchPath are checked
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1673
     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
  1674
     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
  1675
     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
  1676
     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
  1677
     proceed with some replacement image. If unhandled, nil is returned."
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1678
6532
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1679
    |image fn nm inStream suffix readerClass
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1680
     mustDecompress readersErrorMsg|
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1681
4159
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1682
    "before trying each reader, check if the file is readable"
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1683
6532
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1684
    fn := aFileName asFilename.
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1685
    fn isAbsolute ifFalse:[
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1686
        inStream := Smalltalk systemFileStreamFor:fn.
6375
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1687
        inStream isNil ifTrue:[
6532
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1688
            inStream := Smalltalk bitmapFileStreamFor:fn.
6375
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1689
            inStream isNil ifTrue:[
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1690
                "this signal is a query - if noone seems to care, return nil.
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1691
                 However, a handler may provide a replacement image."
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1692
                ^ ImageNotFoundQuerySignal
6532
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1693
                            raiseRequestWith:fn
7176
047e717102d3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7175
diff changeset
  1694
                            errorString:('Image: ''' , fn pathName, ''' does not exist or is not readable').
6375
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1695
            ].
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1696
        ].
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1697
        fn := inStream pathName asFilename.
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1698
        inStream close.
4843
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1699
    ].
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1700
4158
930761d24ab2 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4156
diff changeset
  1701
    nm := fn name.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1702
    suffix := fn suffix.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1703
4159
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1704
    "handle compressed-suffix"
6532
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1705
    (#('gz') includes:suffix) ifTrue:[
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1706
        |baseFn|
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1707
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1708
        baseFn := fn withoutSuffix.
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1709
        nm := baseFn name.
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1710
        suffix := baseFn suffix.
6375
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1711
        mustDecompress := true.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1712
    ].
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1713
    suffix isEmpty ifTrue:[
6375
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1714
        suffix := nm.
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
  1715
    ].
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
  1716
6507
05fb9b9d9e53 class: Image
Claus Gittinger <cg@exept.de>
parents: 6496
diff changeset
  1717
    "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
  1718
    readerClass := MIMETypes imageReaderForSuffix:suffix.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1719
    readerClass notNil ifTrue:[
6375
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1720
        mustDecompress == true ifTrue:[
6532
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1721
            |zipStream|
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1722
            inStream := fn readStream.
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1723
            zipStream := ZipStream readOpenOn:inStream suppressHeaderAndChecksum:true.
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1724
            zipStream notNil ifTrue:[
6375
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1725
                [
6532
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1726
                    image := readerClass fromStream:zipStream.
6375
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1727
                ] ensure:[
6532
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1728
                    zipStream close.
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1729
                    inStream close.
6375
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1730
                ].
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1731
            ]
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1732
        ] ifFalse:[
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1733
            BadImageFormatQuerySignal handle:[:ex |
6586
9d16907daea8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6532
diff changeset
  1734
                BadImageFormatQuerySignal isHandled ifTrue:[ ex reject ].
6375
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1735
                Transcript showCR:(readersErrorMsg := ex description).
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1736
                image := nil.
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1737
                ex return.
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1738
            ] do:[
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1739
                image := readerClass fromFile:fn.
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1740
            ].
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1741
        ].
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1742
        image notNil ifTrue:[^ image].
4159
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1743
    ].
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1744
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1745
    (readerClass isNil or:[readersErrorMsg notNil]) ifTrue:[
6375
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1746
        "no known extension (or wrong extension)
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1747
         - ask all readers if they know this format ...
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1748
         ... these look into the file, and investigate the header.
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1749
         therefore, it takes a bit longer."
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1750
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1751
        MIMETypes imageReaderClasses do:[:mimeReaderClass |
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1752
            (mimeReaderClass notNil
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1753
            and:[mimeReaderClass ~~ readerClass]) ifTrue:[
6532
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1754
               (mimeReaderClass isValidImageFile:fn) ifTrue:[
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1755
                    image := mimeReaderClass fromFile:fn.
6375
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1756
                    image notNil ifTrue:[
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1757
                        ^ image
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1758
                    ]
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1759
                ]
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1760
            ]
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1761
        ].
4159
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1762
    ].
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1763
7175
4bd37cf4075e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7173
diff changeset
  1764
    (fn exists and:[fn isReadable]) ifFalse:[
4bd37cf4075e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7173
diff changeset
  1765
        ^ ImageNotFoundQuerySignal
4bd37cf4075e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7173
diff changeset
  1766
                    raiseRequestWith:fn
7176
047e717102d3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7175
diff changeset
  1767
                    errorString:('Image: ''' , fn pathName, ''' does not exist or is not readable').
7175
4bd37cf4075e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7173
diff changeset
  1768
    ].
4bd37cf4075e #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7173
diff changeset
  1769
    
4159
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1770
    "nope - unknown format
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1771
     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
  1772
     However, a handler may provide a replacement image."
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1773
3656
11670e0e6fcb invalid format notification fixed
Claus Gittinger <cg@exept.de>
parents: 3623
diff changeset
  1774
    ^ BadImageFormatQuerySignal
6532
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1775
        raiseRequestWith:fn
7176
047e717102d3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7175
diff changeset
  1776
        errorString:(readersErrorMsg ? ('Image: unknown image file format: ''' , fn pathName , '''')).
4159
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1777
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1778
    "
6532
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1779
     Image fromFile:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies'
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1780
     Image fromFile:'bitmaps/gifImages/garfield.gif' inPackage:'stx:goodies'
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1781
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1782
     Image fromFile:'bitmaps/winBitmaps/a11.ico' inPackage:'stx:goodies'
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1783
     Image fromFile:'bitmaps/xpmBitmaps/countries/czech.xpm' inPackage:'stx:goodies'
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1784
     Image fromFile:'bitmaps/xpmBitmaps/countries/czech.xpm.gz' inPackage:'stx:goodies'
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1785
     Image fromFile:'Demos/bitmaps/hello_world.icon' inPackage:'stx:clients'
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1786
    "
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1787
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1788
    "
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1789
     Image fromFile:'fooBar'
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1790
    "
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1791
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
  1792
    "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
  1793
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1794
     Image imageNotFoundQuerySignal
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1795
     handle:[:ex |
6375
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1796
        Transcript showCR:ex description.
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1797
        ex proceedWith:nil
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1798
     ] do:[
6375
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1799
         Image fromFile:'fooBar'
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1800
     ]
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1801
    "
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1802
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1803
    "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
  1804
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1805
     Image imageNotFoundQuerySignal
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
  1806
     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
  1807
     do:[
6375
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1808
         Image fromFile:'fooBar'
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1809
     ]
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
4843
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1812
    "Modified: / 19-11-2007 / 15:50:52 / cg"
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1813
!
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1814
3426
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1815
fromFile:aFileName inPackage:aPackage
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1816
    "read an image for a package from a file.
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1817
     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
  1818
     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
  1819
     and lets the appropriate reader read the file.
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1820
     Also, all bitmap directories along the searchPath are checked
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1821
     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
  1822
     separate directory, thereby overriding system bitmaps easily.
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1823
     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
  1824
     the ImageNotFoundQuerySignal is raised, which may be handled to
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1825
     proceed with some replacement image. If unhandled, nil is returned."
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1826
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1827
    ^ Smalltalk imageFromFileNamed:aFileName inPackage:aPackage
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1828
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1829
    "
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1830
     Image fromFile:'libtool/bitmaps/SBrowser.xbm'
3426
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1831
     Image fromFile:'bitmaps/SBrowser.xbm' inPackage:'stx:libtool'
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1832
     Image fromFile:'garfield.gif' inPackage:'stx:goodies/bitmaps/gifImages'
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1833
    "
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1834
!
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1835
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1836
fromFile:aFileName on:aDevice
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1837
    "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
  1838
     Return nil (or whatever a handler returned),
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1839
     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
  1840
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1841
    |img|
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1842
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1843
    img := self fromFile:aFileName.
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1844
    img notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1845
	^ img onDevice:aDevice
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1846
    ].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1847
    ^ nil
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1848
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1849
    "Modified: 1.2.1997 / 14:48:07 / cg"
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1850
!
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1851
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1852
fromFile:aFileName resolution:res
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1853
    "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
  1854
     as appropriate (only req'd for very high resolution displays).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1855
     Return nil (or whatever a handler returned),
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1856
     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
  1857
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1858
    ^ self fromFile:aFileName resolution:res on:nil
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1859
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1860
    "Created: 19.12.1996 / 14:02:13 / cg"
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1861
    "Modified: 1.2.1997 / 14:48:16 / cg"
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1862
!
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1863
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1864
fromFile:aFileName resolution:dpi on:aDevice
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1865
    "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
  1866
     as appropriate (only req'd with very high resolution displays).
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1867
     Prepare a device representation.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1868
     Return nil (or whatever a handler returned),
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1869
     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
  1870
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1871
    |img dev dpiH mag|
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1872
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1873
    img := self fromFile:aFileName.
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1874
    img isNil ifTrue:[^ nil].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1875
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1876
    "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
  1877
    dev := aDevice.
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1878
    dev isNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1879
	"should not happen ..."
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1880
	dev := Screen current
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1881
    ].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1882
3059
0895d23678ac assume 90dpi in #fromFile:resolution: if there is no current display
Claus Gittinger <cg@exept.de>
parents: 3038
diff changeset
  1883
    dev notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1884
	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
  1885
    ] ifFalse:[
0895d23678ac assume 90dpi in #fromFile:resolution: if there is no current display
Claus Gittinger <cg@exept.de>
parents: 3038
diff changeset
  1886
	dpiH := 90
0895d23678ac assume 90dpi in #fromFile:resolution: if there is no current display
Claus Gittinger <cg@exept.de>
parents: 3038
diff changeset
  1887
    ].
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1888
    ((dpi >= (dpiH * 0.75)) and:[dpi <= (dpiH * 1.5)]) ifTrue:[^ img].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1889
    mag := (dpiH / dpi) rounded.
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1890
    mag = 0 ifTrue:[^ img].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1891
    mag = 1 ifTrue:[^ img].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1892
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1893
    img := img magnifiedBy:(mag @ mag).
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1894
    aDevice notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1895
	^ img onDevice:aDevice
1143
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
    ^ img
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1898
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1899
    "Modified: 1.2.1997 / 14:48:20 / cg"
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1900
!
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1901
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1902
fromStream:aStream
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1903
    "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
  1904
     out the file format itself (by contents)
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1905
     and lets the appropriate reader read the file.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1906
     To do this, the stream must be positionable.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1907
     Return nil (or whatever a handler returned),
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1908
     if the stream does not contain an appropriate image."
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1909
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  1910
    |image|
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1911
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1912
    "
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1913
     ask all readers if they know
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1914
     this format ...
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1915
    "
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  1916
    MIMETypes imageReaderClasses do:[:readerClass |
7176
047e717102d3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7175
diff changeset
  1917
        readerClass notNil ifTrue:[
047e717102d3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7175
diff changeset
  1918
            image := readerClass fromStream:aStream.
047e717102d3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7175
diff changeset
  1919
            image notNil ifTrue:[^ image].
047e717102d3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7175
diff changeset
  1920
        ]
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1921
    ].
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1922
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1923
    "
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1924
     nope - unknown format
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1925
    "
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1926
"/    'Image [info]: unknown image file format in stream: ' infoPrintCR.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1927
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1928
    ^ ImageNotFoundQuerySignal
7176
047e717102d3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7175
diff changeset
  1929
                raiseRequestWith:aStream
047e717102d3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7175
diff changeset
  1930
                errorString:('Image [warning]: unknown image file format in stream').
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1931
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1932
    "
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1933
     Image fromFile:'goodies/bitmaps/gifImages/claus.gif'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1934
     Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1935
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1936
     Image fromFile:'clients/Animation/bitmaps/globe1.xbm'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1937
     Image fromFile:'clients/Animation/bitmaps/globe1.xbm.Z'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1938
     Image fromFile:'clients/Demos/bitmaps/hello_world.icon'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1939
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1940
     Image fromFile:'librun/stx.ico'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1941
     Image fromFile:'libwidg3/bitmaps/wall.tiff'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1942
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  1943
     Image fromFile:'goodies/bitmaps/test.fax'
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1944
     Image fromFile:'fileIn/bitmaps/founders.im8'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1945
     Image fromFile:'goodies/faces/next.com/steve.face'
1051
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
    "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
  1949
    "Modified: 30.6.1997 / 22:03:59 / cg"
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1950
!
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
fromStream:aStream using:aReaderClass
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1953
    "read an image from a stream, given an imageReaderClass.
6507
05fb9b9d9e53 class: Image
Claus Gittinger <cg@exept.de>
parents: 6496
diff changeset
  1954
     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
  1955
     extension (or non-definite header), so #fromStream: could not
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1956
     find out the images format.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1957
     Return nil (or whatever a handler returned),
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1958
     if the stream does not contain an appropriate image."
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1959
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1960
    |image|
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1961
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1962
    image := aReaderClass fromStream:aStream.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1963
    image notNil ifTrue:[^ image].
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1964
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1965
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1966
     nope - unknown format
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1967
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1968
"/    'Image [info]: unknown image file format in stream: ' infoPrintCR.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1969
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1970
    ^ ImageNotFoundQuerySignal
6507
05fb9b9d9e53 class: Image
Claus Gittinger <cg@exept.de>
parents: 6496
diff changeset
  1971
                raiseRequestWith:aStream
7176
047e717102d3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7175
diff changeset
  1972
                errorString:('Image: unknown image file format in stream').
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1973
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1974
    "Created: 1.2.1997 / 14:46:20 / cg"
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1975
    "Modified: 1.2.1997 / 14:48:53 / cg"
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1976
! !
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1977
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  1978
!Image class methodsFor:'misc'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1979
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1980
ditherAlgorithm
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1981
    "return the way we dither -
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1982
	#threshold, or nil        -> no dither
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1983
	#pattern, or #ordered     -> orderedDither (ugly, but fast)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1984
	#error or #floydSteinberg -> errorDiffusion; much better
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1985
	#burkes                   -> errorDiffusion; even better."
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1986
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1987
    ^ DitherAlgorithm
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1988
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1989
    "Created: 17.6.1996 / 18:57:47 / cg"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1990
!
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1991
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1992
ditherAlgorithm:aSymbol
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1993
    "define how to dither -
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1994
	#threshold, or nil        -> no dither
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1995
	#pattern, or #ordered     -> orderedDither (ugly, but fast)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1996
	#error or #floydSteinberg -> errorDiffusion; much better
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1997
	#burkes                   -> errorDiffusion; even better."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1998
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1999
    DitherAlgorithm := aSymbol
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2000
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2001
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2002
     Image dither:#pattern
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2003
     Image dither:#floydSteinberg
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2004
     Image dither:#burkes
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2005
     Image dither:nil
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2006
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2007
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2008
    "Modified: 10.6.1996 / 12:27:09 / cg"
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  2009
    "Created: 17.6.1996 / 18:57:19 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2010
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2011
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2012
numberOfDitherColors:n
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2013
    "define how many colors (i.e. patterns) to use when
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2014
     doing a pattern dither"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2015
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2016
    NumberOfDitherColors := n
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2017
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2018
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2019
orderedDitherMatrixOfSize:sz
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2020
    sz == 2 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2021
	^ #[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2022
		0 2
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2023
		3 1
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2024
	   ].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2025
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2026
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2027
    sz == 4 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2028
	^ #[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2029
		 0  8  2 10
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2030
		12  4 14  6
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2031
		 3 11  1  9
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2032
		15  7 13  5
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2033
	   ].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2034
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2035
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2036
    sz == 8 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2037
	^  #[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2038
		0 32  8 40    2 34 10 42
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2039
	       48 16 56 24   50 18 58 26
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2040
	       12 44  4 36   14 46  6 38
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2041
	       60 28 52 20   62 30 54 22
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2042
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2043
		3 35 11 43    1 33  9 41
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2044
	       51 19 59 27   49 17 57 25
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2045
	       15 47  7 39   13 45  5 37
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2046
	       63 31 55 23   61 29 53 21
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2047
	    ].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2048
    ].
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
    ^ nil
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2051
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2052
    "Created: 7.6.1996 / 14:15:05 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2053
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2054
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  2055
!Image class methodsFor:'queries'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2056
2005
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2057
bytesPerRowForWidth:width depth:bitsPerPixel padding:padding
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2058
    "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
  2059
     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
  2060
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2061
    |bitsPerRow paddedUnitsPerRow|
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2062
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2063
    bitsPerRow := width * bitsPerPixel.
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2064
    paddedUnitsPerRow := bitsPerRow // padding.
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2065
    ((bitsPerRow \\ padding) ~~ 0) ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  2066
	paddedUnitsPerRow := paddedUnitsPerRow + 1
2005
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2067
    ].
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2068
    ^ paddedUnitsPerRow * (padding // 8)
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2069
5126
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  2070
    "
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  2071
     self bytesPerRowForWidth:7 depth:1 padding:8
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  2072
     self bytesPerRowForWidth:7 depth:1 padding:16
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  2073
     self bytesPerRowForWidth:7 depth:1 padding:32
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  2074
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  2075
     self bytesPerRowForWidth:15 depth:1 padding:8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  2076
     self bytesPerRowForWidth:15 depth:1 padding:16
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  2077
     self bytesPerRowForWidth:15 depth:1 padding:32
5126
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  2078
    "
2005
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2079
!
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2080
6797
161685b0d113 class: Image
Claus Gittinger <cg@exept.de>
parents: 6755
diff changeset
  2081
defaultImageFileWriter
161685b0d113 class: Image
Claus Gittinger <cg@exept.de>
parents: 6755
diff changeset
  2082
    "only used, if a file is saved with no particular extension
161685b0d113 class: Image
Claus Gittinger <cg@exept.de>
parents: 6755
diff changeset
  2083
     or explicit writer given.
161685b0d113 class: Image
Claus Gittinger <cg@exept.de>
parents: 6755
diff changeset
  2084
     For now, default to tiff format.
161685b0d113 class: Image
Claus Gittinger <cg@exept.de>
parents: 6755
diff changeset
  2085
     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
  2086
161685b0d113 class: Image
Claus Gittinger <cg@exept.de>
parents: 6755
diff changeset
  2087
    ^ TIFFReader
161685b0d113 class: Image
Claus Gittinger <cg@exept.de>
parents: 6755
diff changeset
  2088
!
161685b0d113 class: Image
Claus Gittinger <cg@exept.de>
parents: 6755
diff changeset
  2089
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2090
defaultPhotometric
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  2091
    "return the default photometric pixel interpretation.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  2092
     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
  2093
     Much better would be to always have some (possibly fake and virtual) colormap around, and ask that one.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  2094
     However, in the meantime, many other classes depend on that, so that it should be kept as an API 
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  2095
     - 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
  2096
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2097
    ^ #blackIs0
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2098
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2099
    "Modified: 20.4.1996 / 23:40:41 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2100
    "Created: 10.6.1996 / 18:08:12 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2101
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2102
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2103
imageDepth
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2104
    "return the depth of images represented by instances of
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2105
     this class.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2106
     Must be redefined in concrete subclasses"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2107
2913
c51ac85e9aa2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2891
diff changeset
  2108
    ^ self subclassResponsibility
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2109
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2110
    "Modified: 20.4.1996 / 23:40:41 / cg"
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  2111
!
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  2112
1306
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  2113
imageFileSuffixes
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  2114
    "return a collection of suffixes which are recognized as image-file suffix"
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  2115
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  2116
    ^ MIMETypes imageFileSuffixes
1306
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  2117
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  2118
    "
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  2119
     Image imageFileSuffixes
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  2120
    "
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  2121
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  2122
    "Modified: 30.6.1997 / 22:04:39 / cg"
1306
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  2123
!
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  2124
1783
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2125
imageReaderClassForMIME:mimeType
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2126
    "return an appropriate imageReader class for a given mime type;
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2127
     nil if there is none (or it did not install itself)"
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2128
1801
3dff7fb2bd59 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1800
diff changeset
  2129
    ^ MIMETypes imageReaderForType:mimeType
1783
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2130
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2131
    "
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2132
     Image imageReaderClassForMIME:'image/tiff'
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2133
     Image imageReaderClassForMIME:'image/x-portable-pixmap'
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2134
    "
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2135
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2136
    "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
  2137
    "Modified: 30.6.1997 / 21:54:10 / cg"
1783
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2138
!
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2139
1572
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  2140
imageReaderClassForSuffix:aSuffix
1783
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2141
    "return an appropriate imageReader class for a given file-suffix;
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2142
     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
  2143
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  2144
    ^ MIMETypes imageReaderForSuffix:aSuffix
1572
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  2145
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  2146
    "
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  2147
     Image imageReaderClassForSuffix:'tiff'
1783
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2148
     Image imageReaderClassForSuffix:'foo'
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2149
    "
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2150
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  2151
    "Modified: 30.6.1997 / 22:05:14 / cg"
1572
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  2152
!
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  2153
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  2154
implementorForDepth:depth
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2155
    "return the class, which best implements images of depth"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2156
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2157
    depth == 1 ifTrue:[^ Depth1Image].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2158
    depth == 2 ifTrue:[^ Depth2Image].
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  2159
    depth <= 4 ifTrue:[^ Depth4Image].
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  2160
    depth <= 8 ifTrue:[^ Depth8Image].
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  2161
    depth <= 16 ifTrue:[^ Depth16Image].
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  2162
    depth <= 24 ifTrue:[^ Depth24Image].
1664
42b1af0353c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1662
diff changeset
  2163
    depth <= 32 ifTrue:[^ Depth32Image].
5299
6b1d1dcf5c85 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5237
diff changeset
  2164
    depth <= 48 ifTrue:[^ Depth48Image].
5313
7c40ea0163ee *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
  2165
    depth <= 64 ifTrue:[^ Depth64Image].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2166
    ^ self
1664
42b1af0353c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1662
diff changeset
  2167
42b1af0353c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1662
diff changeset
  2168
    "Modified: 24.4.1997 / 19:04:52 / cg"
1611
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2169
!
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2170
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2171
isImageFileSuffix:aSuffix
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2172
    "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
  2173
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2174
     ^ self imageFileSuffixes includes:(aSuffix asLowercase)
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2175
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2176
    "
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2177
     Image isImageFileSuffix:'gif'
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2178
     Image isImageFileSuffix:'xbm'
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2179
     Image isImageFileSuffix:'foo'
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2180
    "
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2181
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2182
    "Created: 18.4.1997 / 14:55:28 / cg"
1786
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2183
!
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2184
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2185
mimeTypeFromSuffix:suffix
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2186
    "search my suffix information for a mime type and
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2187
     return it; return nil if unknown"
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2188
1802
9a3d7c669727 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2189
    ^ MIMETypes mimeTypeForSuffix:suffix
1786
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2190
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2191
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2192
     Image mimeTypeFromSuffix:'gif'
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2193
     Image mimeTypeFromSuffix:'tiff'
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2194
     Image mimeTypeFromSuffix:'foobar'
1786
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2195
    "
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2196
1802
9a3d7c669727 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2197
    "Modified: 1.7.1997 / 00:17:27 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2198
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2199
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  2200
!Image class methodsFor:'screen capture'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2201
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2202
fromScreen
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2203
    "return an image of the full screen.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2204
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2205
	      it may not work from within a buttonMotion
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2206
	      (use #fromScreen:on:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2207
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2208
    |display|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2209
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2210
    display := Screen current.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2211
    ^ self
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2212
	fromScreen:(0@0 corner:(display width @ display height))
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2213
	on:display
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2214
	grab:true
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2215
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2216
    "
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2217
     Image fromScreen
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2218
     Image fromScreen inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2219
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2220
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2221
    "Modified: 26.3.1997 / 10:44:55 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2222
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2223
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2224
fromScreen:aRectangle
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2225
    "return an image of a part of the screen.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2226
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2227
	      it may not work from within a buttonMotion
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2228
	      (use #fromScreen:on:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2229
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2230
    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2231
	fromScreen:aRectangle
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2232
	on:Screen current
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2233
	grab:true
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2234
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2235
    "
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2236
     Image fromScreen:(0@0 corner:100@100)
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2237
     (Image fromScreen:(0@0 corner:100@100)) inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2238
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2239
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2240
    "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
  2241
!
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2242
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2243
fromScreen:aRectangle on:aDevice
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2244
    "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
  2245
     another display device.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2246
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2247
	      it may not work from within a buttonMotion
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2248
	      (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
  2249
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2250
    ^ self
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2251
	fromScreen:aRectangle
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2252
	on:aDevice
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2253
	grab:true
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2254
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2255
    "
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2256
     Image fromScreen:(0@0 corner:100@100)
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2257
    "
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2258
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2259
    "get a snapshot of your friends screen ...
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2260
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2261
     |dpy2|
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2262
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2263
     dpy2 := XWorkstation new initializeFor:'idefix:0'.
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2264
     (Image fromScreen:(dpy2 bounds) on:dpy2) inspect
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2265
    "
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2266
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2267
    "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
  2268
!
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
fromScreen:aRectangle on:aDisplay grab:doGrab
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2271
    "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
  2272
     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
  2273
     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
  2274
     shown while the readout is done.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2275
     WARNING: with doGrab true, this temporarily grabs the display
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2276
	      and it may not work from within a buttonMotion
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2277
	      (use with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2278
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2279
    |depth vis img|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2280
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2281
    depth := aDisplay depth.
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2282
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2283
    "/
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2284
    "/ 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
  2285
    "/ (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
  2286
    "/  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
  2287
    "/
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2288
    vis := aDisplay visualType.
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2289
    (vis == #TrueColor or:[vis == #DirectColor]) ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2290
	depth > 8 ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2291
	    depth := 24.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2292
	]
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2293
    ].
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2294
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  2295
    img := self newForDepth:depth.
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2296
    ^ img fromScreen:aRectangle on:aDisplay grab:doGrab
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2297
2019
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
  2298
    "Modified: / 26.1.1998 / 22:23:08 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2299
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2300
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2301
fromScreenArea
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2302
    "return an image of a part of the screen;
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2303
     let user specify screen area.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2304
     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
  2305
     Use #fromUser for ST-80 compatibility.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2306
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2307
	      it may not work from within a buttonMotion
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2308
	      (use #fromScreen:on:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2309
2102
7c7d11aa956e care for empty rectangle in Image>>fromScreenArea
Claus Gittinger <cg@exept.de>
parents: 2081
diff changeset
  2310
    |r|
7c7d11aa956e care for empty rectangle in Image>>fromScreenArea
Claus Gittinger <cg@exept.de>
parents: 2081
diff changeset
  2311
2323
bf88727c4dee wait until button is released in #fromUser.
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  2312
    [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
  2313
    r := Rectangle fromUser.
7c7d11aa956e care for empty rectangle in Image>>fromScreenArea
Claus Gittinger <cg@exept.de>
parents: 2081
diff changeset
  2314
    r width == 0 ifTrue:[^ nil].
7c7d11aa956e care for empty rectangle in Image>>fromScreenArea
Claus Gittinger <cg@exept.de>
parents: 2081
diff changeset
  2315
    r height == 0 ifTrue:[^ nil].
7c7d11aa956e care for empty rectangle in Image>>fromScreenArea
Claus Gittinger <cg@exept.de>
parents: 2081
diff changeset
  2316
    ^ self fromScreen:r
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2317
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2318
    "
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2319
     Image fromScreenArea
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2320
     Image fromScreenArea inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2321
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2322
2323
bf88727c4dee wait until button is released in #fromUser.
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  2323
    "Modified: / 10.9.1998 / 15:59:58 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2324
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2325
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2326
fromUser
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2327
    "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
  2328
     Same as fromScreenArea, for ST-80 compatibility.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2329
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2330
	      it may not work from within a buttonMotion
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2331
	      (use #fromScreen:on:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2332
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2333
    ^ self fromScreenArea
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2334
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2335
    "
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2336
     Image fromUser
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2337
     Image fromUser inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2338
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2339
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2340
    "Modified: 26.3.1997 / 10:45:25 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2341
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2342
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2343
fromView:aView
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2344
    "return an image taken from a views contents as currently
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2345
     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
  2346
     as the Display.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2347
     Notice, that for invisible or partial covered views,
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2348
     the returned Image is NOT correct.
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2349
     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
  2350
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2351
	      it may not work from within a buttonMotion
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2352
	      (use #fromView:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2353
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2354
    ^ self
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2355
	fromView:aView
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2356
	grab:true
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  2357
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  2358
    "
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2359
     Image fromView:(Launcher allInstances first window topView)
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2360
     Image fromView:(BrowserView allInstances first topView)
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2361
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2362
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2363
    "get a snapshot from whichever view is active:
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2364
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2365
     |active|
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2366
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2367
     active := WindowGroup activeGroup topViews first.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2368
     (Image fromView:active) inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2369
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2370
1043
0688425d02c9 Rename Launcher-->OldLauncher, NewLauncher-->Launcher.
Stefan Vogel <sv@exept.de>
parents: 1041
diff changeset
  2371
    "Modified: 9.9.1996 / 22:41:01 / stefan"
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2372
    "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
  2373
!
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2374
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2375
fromView:aView grab:doGrab
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2376
    "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
  2377
     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
  2378
     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
  2379
     shown while the readout is done.
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2380
     The returned image has the same depth and photometric
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2381
     as the Display.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2382
     Notice, that for invisible or partial covered views,
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2383
     the returned Image is NOT correct.
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2384
     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
  2385
     WARNING: with doGrab true, this temporarily grabs the display
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2386
	      and it may not work from within a buttonMotion
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2387
	      (use with a false grabArg then)."
4540
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2388
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2389
    ^ self fromView:aView grab:doGrab withDecoration:false
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2390
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2391
    "Created: / 26.3.1997 / 10:34:20 / cg"
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2392
    "Modified: / 10.10.2001 / 14:13:29 / cg"
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2393
!
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2394
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2395
fromView:aView grab:doGrab withDecoration:withDecoration
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2396
    "return an image taken from a views contents as currently
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2397
     on the screen, optionally with decoration included.
4540
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2398
     If the doGrab argument is true, the display
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2399
     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
  2400
     shown while the readout is done.
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2401
     The returned image has the same depth and photometric
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2402
     as the Display.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2403
     Notice, that for invisible or partial covered views,
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2404
     the returned Image is NOT correct.
4540
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2405
     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
  2406
     WARNING: with doGrab true, this temporarily grabs the display
6370
9e3a18c732ca class: Image
Claus Gittinger <cg@exept.de>
parents: 6311
diff changeset
  2407
              and it may not work from within a buttonMotion
9e3a18c732ca class: Image
Claus Gittinger <cg@exept.de>
parents: 6311
diff changeset
  2408
              (use with a false grabArg then)."
4540
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2409
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2410
    |org ext device cH bW bH|
3518
983e7730a905 use new translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents: 3507
diff changeset
  2411
983e7730a905 use new translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents: 3507
diff changeset
  2412
    device := aView graphicsDevice.
983e7730a905 use new translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents: 3507
diff changeset
  2413
    org := device translatePoint:(0@0) fromView:aView toView:nil.
4540
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2414
    ext := aView extent.
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2415
    withDecoration ifTrue:[
6370
9e3a18c732ca class: Image
Claus Gittinger <cg@exept.de>
parents: 6311
diff changeset
  2416
        device isWindowsPlatform ifTrue:[
9e3a18c732ca class: Image
Claus Gittinger <cg@exept.de>
parents: 6311
diff changeset
  2417
            cH := device captionHeight.
9e3a18c732ca class: Image
Claus Gittinger <cg@exept.de>
parents: 6311
diff changeset
  2418
            bW := (device getSystemMetrics: #SM_CXFRAME )
9e3a18c732ca class: Image
Claus Gittinger <cg@exept.de>
parents: 6311
diff changeset
  2419
                  "+ ( device getSystemMetrics: #borderFrameWidth )".
9e3a18c732ca class: Image
Claus Gittinger <cg@exept.de>
parents: 6311
diff changeset
  2420
            bH := (device getSystemMetrics: #SM_CYFRAME )
9e3a18c732ca class: Image
Claus Gittinger <cg@exept.de>
parents: 6311
diff changeset
  2421
                  " + ( device getSystemMetrics: #borderFrameHeight )".
9e3a18c732ca class: Image
Claus Gittinger <cg@exept.de>
parents: 6311
diff changeset
  2422
            org := org - (bW @ (bH + cH)).
9e3a18c732ca class: Image
Claus Gittinger <cg@exept.de>
parents: 6311
diff changeset
  2423
            ext := ext + ((bW + bW) @ (bH+bH+cH)).
9e3a18c732ca class: Image
Claus Gittinger <cg@exept.de>
parents: 6311
diff changeset
  2424
        ].
4540
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2425
    ].
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2426
    ^ self fromScreen:(org extent:ext) on:device grab:doGrab
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2427
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2428
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2429
     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
  2430
     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
  2431
    "
3518
983e7730a905 use new translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents: 3507
diff changeset
  2432
4574
4b65895bbb6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4565
diff changeset
  2433
    "Created: / 26-03-1997 / 10:34:20 / cg"
4b65895bbb6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4565
diff changeset
  2434
    "Modified: / 08-09-2006 / 15:41:41 / cg"
157
claus
parents: 154
diff changeset
  2435
! !
claus
parents: 154
diff changeset
  2436
3880
c4c8268a2d9f method category rename
Claus Gittinger <cg@exept.de>
parents: 3876
diff changeset
  2437
!Image methodsFor:'Compatibility-Squeak'!
3475
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2438
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2439
boundingBox
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2440
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2441
    ^ self bounds
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2442
!
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2443
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2444
colormapIfNeededForDepth:d
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2445
    ^ nil
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2446
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2447
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2448
!
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2449
6308
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2450
colorsFromArray:anArrayOfRGBTriples
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2451
    "for squeak compatibility with ColorForm:
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2452
     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
  2453
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2454
    |newMap|
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2455
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2456
    newMap := Colormap new:anArrayOfRGBTriples size.
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2457
    anArrayOfRGBTriples doWithIndex:[:rgb :i |
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2458
        newMap at:i putRGBTriple:rgb
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2459
    ].
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2460
    self colorMap:newMap.
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2461
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2462
    "
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2463
     Depth8Image new
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2464
        colorsFromArray:#( (0.5 0.5 0.5) (0.25 0.0 0.0) (0.0 0.25 0.5))
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2465
    "
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2466
!
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2467
3475
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2468
fill:aRectangle fillColor:aColor
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2469
    "fill the rectangular area specified by aRectangle with the given color"
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2470
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2471
    self fillRectangle:aRectangle withColor:aColor
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2472
!
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2473
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2474
fillBlack:aRectangle
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2475
    "fill the rectangular area specified by aRectangle with the black color"
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2476
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2477
    self fillRectangle:aRectangle withColor:Color black
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2478
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2479
    "
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2480
     |img|
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2481
     img := Image extent:100@100 depth:24.
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2482
     img photometric:#rgb.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2483
     img data:(ByteArray new:100*100*3).
3475
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2484
     img fillWhite:(0@0 corner:100@100).
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2485
     img fillBlack:(10@10 corner:90@90).
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2486
     img inspect.
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2487
    "
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
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2490
fillWhite:aRectangle
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2491
    "fill the rectangular area specified by aRectangle with the white color"
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
    self fillRectangle:aRectangle withColor:Color white
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2494
!
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2495
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2496
isTransparentAt:aPoint
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2497
    mask isNil ifTrue:[ ^ false].
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2498
    ^ (mask pixelAt:aPoint) == 0
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2499
! !
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2500
3880
c4c8268a2d9f method category rename
Claus Gittinger <cg@exept.de>
parents: 3876
diff changeset
  2501
!Image methodsFor:'Compatibility-VW'!
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2502
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2503
asCachedImage
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2504
    "return the receiver associated to the current screens device.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2505
     For ST-80 compatibility
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2506
     (ST/X uses Image for both device- and nonDevice-images)"
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2507
2832
793500016a2b #on: -> #onDevice:
Claus Gittinger <cg@exept.de>
parents: 2801
diff changeset
  2508
    ^ self onDevice:Screen current
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2509
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2510
    "Modified: 23.4.1996 / 11:10:32 / cg"
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2511
!
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2512
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2513
asRetainedMedium
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2514
    "return the receiver associated to the current screens device.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2515
     For ST-80 compatibility
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2516
     (ST/X uses Image for both device- and nonDevice-images)"
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2517
2832
793500016a2b #on: -> #onDevice:
Claus Gittinger <cg@exept.de>
parents: 2801
diff changeset
  2518
    ^ self onDevice:Screen current
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2519
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2520
    "Modified: 23.4.1996 / 11:10:32 / cg"
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2521
    "Created: 27.1.1997 / 15:49:08 / cg"
1325
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2522
!
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2523
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2524
bounds:newBounds
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2525
    ^ self
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2526
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2527
    "Created: 10.2.1997 / 12:44:46 / cg"
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2528
!
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2529
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2530
containsPoint:aPoint
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2531
    "in st-80, images are visualComponents ..."
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2532
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2533
    ^ self bounds containsPoint:aPoint
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2534
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2535
    "Created: 6.3.1997 / 15:24:12 / cg"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2536
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2537
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2538
convertToPalette:aColormap renderedBy:anImageRenderer
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2539
    "this does not really mimicri the corresponding ST-80 functionality"
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2540
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2541
    |monoBits convertedImage|
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2542
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2543
    aColormap size == 2 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2544
	anImageRenderer class == OrderedDither ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2545
	    monoBits := self orderedDitheredMonochromeBits.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2546
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2547
	    monoBits := self floydSteinbergDitheredMonochromeBits.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2548
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2549
	(((aColormap at:1) = Color black)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2550
	and:[(aColormap at:2) = Color white]) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2551
	    "/ ok
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2552
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2553
	    (((aColormap at:1) = Color white)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2554
	    and:[(aColormap at:2) = Color black]) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2555
		monoBits invert
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2556
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2557
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2558
	convertedImage := Depth1Image width:width height:height fromArray:monoBits.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2559
	convertedImage palette:aColormap.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2560
	^ convertedImage
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2561
    ].
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2562
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2563
    self error:'unimplemented operation'.
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2564
    ^ self
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2565
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2566
    "Modified: 1.3.1997 / 17:25:50 / cg"
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2567
!
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2568
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2569
paintBasis
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2570
    "huh - whats that;
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2571
     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
  2572
     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
  2573
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2574
    ^ ColorValue
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2575
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2576
    "Created: 6.3.1997 / 15:24:19 / cg"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2577
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2578
1325
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2579
preferredBounds
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2580
    ^ self bounds
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2581
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2582
    "Created: 10.2.1997 / 12:42:36 / cg"
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2583
!
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2584
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2585
tile:bounds from:origin in:tile rule:rule
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2586
    |orgX orgY tW tH|
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2587
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2588
    origin ~= (0@0) ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  2589
	self shouldImplement.
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2590
    ].
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2591
    bounds ~= self bounds ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  2592
	self shouldImplement.
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2593
    ].
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2594
    rule ~= #over ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  2595
	self shouldImplement.
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2596
    ].
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2597
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2598
    orgX := origin x.
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2599
    orgY := origin y.
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2600
    tW := tile width.
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2601
    tH := tile height.
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2602
    (bounds top) to:(bounds bottom) by:tH do:[:dstY |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  2603
	(bounds left) to:(bounds right) by:(tile width) do:[:dstX |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  2604
	    self
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  2605
		copyFrom:tile
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  2606
		x:orgX y:orgY
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  2607
		toX:dstX y:dstY
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  2608
		width:tW height:tH.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  2609
	].
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2610
    ].
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2611
!
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2612
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2613
valueAtPoint:aPoint put:aColorValue
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2614
    aColorValue isInteger ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2615
	self colorAtX:aPoint x y:aPoint y put:aColorValue
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2616
    ] ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2617
	self pixelAtX:aPoint x y:aPoint y put:aColorValue
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2618
    ]
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2619
! !
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2620
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2621
!Image methodsFor:'accessing'!
48194c26a46c Initial revision
claus
parents:
diff changeset
  2622
6912
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2623
bitsARGB32
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2624
    | bitsARGB32 |
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2625
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2626
    bitsARGB32 := ByteArray new: width * height * 4.
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2627
    self bitsARGB32Into: bitsARGB32.
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2628
    ^ bitsARGB32
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2629
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2630
    "Created: / 01-09-2015 / 18:02:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2631
!
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2632
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2633
bitsARGB32Into: buffer
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2634
    self bitsARGB32Into: buffer startingAt: 1
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2635
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2636
    "Created: / 01-09-2015 / 17:18:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2637
!
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2638
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2639
bitsARGB32Into: buffer startingAt: first
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2640
    self bitsARGB32Into: buffer startingAt: first stride: width
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2641
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2642
    "Created: / 01-09-2015 / 17:18:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2643
!
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2644
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2645
bitsARGB32Into: buffer startingAt: first stride: stride
7170
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2646
    "Store each pixel is a 32-bit quantity, with alpha in the upper 
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2647
     8 bits, then red, then green, then blue. The 32-bit quantities are 
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2648
     stored native-endian. Pre-multiplied alpha is used. (That is, 50% 
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2649
     transparent red is 0x80800000, not 0x80ff0000.)"
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2650
6912
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2651
    mask isNil ifTrue:[ 
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2652
        0 to: height - 1 do:[:y |  
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2653
            | base |
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2654
            base := (first - 1) + (y * stride).
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2655
            0 to: width - 1 do:[:x |  
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2656
                | pixel color offset |
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2657
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2658
                offset := base + (x * 4).    
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2659
                pixel := self pixelAtX: x y: y.
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2660
                color := self colorFromValue: pixel.
7170
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2661
                buffer at: (offset + ARGB_R_OFFSET_MACHINE) put: color redByte.  
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2662
                buffer at: (offset + ARGB_G_OFFSET_MACHINE) put: color greenByte.  
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2663
                buffer at: (offset + ARGB_B_OFFSET_MACHINE) put: color blueByte.  
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2664
                buffer at: (offset + ARGB_A_OFFSET_MACHINE) put: 16rFF.   
6912
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2665
            ]
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2666
        ]
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2667
    ] ifFalse:[ 
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2668
    mask depth == 1 ifTrue:[ 
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2669
        0 to: height - 1 do:[:y |  
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2670
            | base |
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2671
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2672
            base := (first - 1) + (y * stride).
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2673
            0 to: width - 1 do:[:x |  
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2674
                | pixel color offset |
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2675
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2676
                offset := base + (x * 4).
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2677
                (mask pixelAtX: x y:y) ifTrue:[ 
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2678
                    pixel := self pixelAtX: x y: y.
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2679
                    color := self colorFromValue: pixel.
7170
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2680
                    buffer at: (offset + ARGB_R_OFFSET_MACHINE) put: color redByte.  
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2681
                    buffer at: (offset + ARGB_G_OFFSET_MACHINE) put: color greenByte.  
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2682
                    buffer at: (offset + ARGB_B_OFFSET_MACHINE) put: color blueByte.  
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2683
                    buffer at: (offset + ARGB_A_OFFSET_MACHINE) put: 16rFF.
6912
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2684
                ] ifFalse:[ 
7170
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2685
                    buffer at: (offset + ARGB_R_OFFSET_MACHINE) put: 0.  
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2686
                    buffer at: (offset + ARGB_G_OFFSET_MACHINE) put: 0.  
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2687
                    buffer at: (offset + ARGB_B_OFFSET_MACHINE) put: 0.  
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2688
                    buffer at: (offset + ARGB_A_OFFSET_MACHINE) put: 0.
6912
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2689
                ].
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2690
            ]
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2691
        ]
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2692
    ] ifFalse:[ 
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2693
    mask depth == 8 ifTrue:[ 
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2694
        0 to: height - 1 do:[:y |  
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2695
            | base |
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2696
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2697
            base := (first - 1) + (y * stride).
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2698
            0 to: width - 1 do:[:x |  
7170
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2699
                | pixel color offset alpha |
6912
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2700
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2701
                offset := base + (x * 4).
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2702
                pixel := self pixelAtX: x y: y.
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2703
                color := self colorFromValue: pixel.
7170
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2704
                alpha := mask pixelAtX: x y:y.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2705
                buffer at: (offset + ARGB_R_OFFSET_MACHINE) put: (color redByte * alpha) // 16rFF.  
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2706
                buffer at: (offset + ARGB_G_OFFSET_MACHINE) put: (color greenByte * alpha) // 16rFF.  
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2707
                buffer at: (offset + ARGB_B_OFFSET_MACHINE) put: (color blueByte * alpha) // 16rFF.  
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2708
                buffer at: (offset + ARGB_A_OFFSET_MACHINE) put: alpha
6912
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2709
            ]
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2710
        ]
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2711
    ]]].
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2712
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2713
    "Created: / 01-09-2015 / 17:16:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
7170
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2714
    "Modified: / 28-02-2016 / 14:38:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
6912
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2715
!
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2716
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2717
bitsPerSample
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2718
    "return the number of bits per sample.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2719
     The return value is an array of bits-per-plane."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2720
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2721
    bitsPerSample notNil ifTrue:[^ bitsPerSample].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2722
    ^ Array with:self depth
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2723
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2724
    "Modified: 10.6.1996 / 18:04:21 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2725
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2726
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2727
colorMap
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2728
    "return the colormap"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2729
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2730
    ^ colorMap
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2731
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2732
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2733
colorMap:aColorMap
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2734
    "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
  2735
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2736
    |newSize "{ Class: SmallInteger }"
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2737
     oldSize "{ Class: SmallInteger }"
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2738
     sameColors|
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2739
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2740
    (aColorMap isNil and:[colorMap isNil]) ifTrue:[^ self].
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2741
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2742
    sameColors := false.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2743
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2744
    photometric == #palette ifTrue:[
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2745
        "/ any change at all ?
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2746
        (newSize := aColorMap size) >= (oldSize := colorMap size) ifTrue:[
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2747
            sameColors := true.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2748
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2749
            1 to:oldSize do:[:idx |
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2750
                (aColorMap at:idx) = (colorMap at:idx) ifFalse:[
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2751
                    sameColors := false.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2752
                ]
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2753
            ].
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2754
        ].
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2755
    ].
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2756
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2757
    self setColorMap:aColorMap.
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2758
    sameColors ifTrue:[
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2759
        ^ self
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2760
    ].
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2761
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  2762
    colorMap notNil ifTrue:[
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2763
        photometric := #palette.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  2764
    ] ifFalse:[
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2765
        (photometric == #palette) ifTrue:[
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2766
            photometric := #blackIs0
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2767
        ]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  2768
    ].
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2769
    deviceForm notNil ifTrue:[
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2770
        self release
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2771
    ]
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2772
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2773
    "Modified: / 31.8.1995 / 03:05:59 / claus"
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2774
    "Modified: / 22.8.1998 / 12:29:58 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2775
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2776
2068
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
  2777
colorMapFromArray: anArray
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2778
    "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
  2779
     The (byte-)Array argument should be of the form:
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2780
	#( 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
  2781
     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
  2782
3876
f4dc6267a30a getting rid of colorMap
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  2783
    self colorMap:(MappedPalette rgbBytesVector:anArray)
3864
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
  2784
!
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
  2785
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
  2786
colorMapFromRGBValueArray:anArray
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2787
    "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
  2788
     The (integer-)Array argument should be of the form:
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2789
	#( rgb0 rgb1  ... rgbN)
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2790
     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
  2791
3876
f4dc6267a30a getting rid of colorMap
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  2792
    self colorMap:(MappedPalette rgbValueVector:anArray)
2068
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
  2793
!
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
  2794
757
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2795
container:aVisualContainer
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2796
    "ignored here - added to allow images to be used like
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2797
     VisualComponents (later, Image should inherit from it)"
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2798
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2799
    "Created: 28.5.1996 / 23:43:49 / cg"
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2800
    "Modified: 29.5.1996 / 10:22:23 / cg"
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2801
!
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2802
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2803
depth
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2804
    "return the depth of the image"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2805
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2806
    ^ self bitsPerPixel
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2807
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2808
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2809
device
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2810
    "return the device, the receiver is associated with.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2811
     Return nil, if the image is unassigned."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2812
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2813
    ^ device
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2814
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2815
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2816
extent
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2817
    "return the images extent"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2818
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2819
    ^ width@height
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2820
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2821
1950
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2822
fileName
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2823
    "return the value of the instance variable 'fileName' (automatically generated)"
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2824
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2825
    ^ fileName
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2826
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2827
    "Created: / 3.11.1997 / 14:54:46 / cg"
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2828
!
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2829
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2830
fileName:something
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2831
    "set the value of the instance variable 'fileName' (automatically generated)"
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2832
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2833
    fileName := something.
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2834
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2835
    "Created: / 3.11.1997 / 14:54:46 / cg"
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2836
!
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2837
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2838
fullColorId
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2839
    "return the id of the full color image on the device.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2840
     Return nil, if the image is unassigned."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2841
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2842
    fullColorDeviceForm isNil ifTrue:[^ nil].
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2843
    ^ fullColorDeviceForm id
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2844
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2845
728
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  2846
graphicsDevice
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  2847
    "same as #device - for ST-80 compatibility"
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  2848
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  2849
    ^ device
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  2850
!
744
db883c9b74b8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 728
diff changeset
  2851
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2852
height
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2853
    "return the height of the image"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2854
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2855
    ^ height
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2856
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2857
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2858
id
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2859
    "return the id of the image on the device.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2860
     Return nil, if the image is unassigned."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2861
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2862
    deviceForm isNil ifTrue:[^ nil].
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2863
    ^ deviceForm id
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2864
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2865
2081
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2866
imageSequence
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2867
    "return the frameSequence of which this image is a part of;
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2868
     nil if it is not part of a sequence."
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2869
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2870
    ^ imageSequence
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2871
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2872
    "Created: / 1.4.1998 / 14:43:00 / cg"
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2873
!
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2874
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2875
imageSequence:aCollection
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2876
    "private entry for imageReaders - set the frameSequence of which
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2877
     this image is a part of"
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2878
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2879
    imageSequence := aCollection
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2880
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2881
    "Created: / 1.4.1998 / 14:42:36 / cg"
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2882
!
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2883
896
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2884
mask
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2885
    ^ mask
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2886
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2887
    "Created: 21.6.1996 / 12:57:44 / cg"
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2888
!
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2889
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2890
mask:anotherImage
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2891
    "set the images mask - currently, this may be nil or a Depth1Image.
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2892
     (it is planned to support alpha information in a Depth8 maskImage in
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2893
      the near future).
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2894
     For depth1 masks: each pixel of the image where a corresponding
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2895
		       1-bit is present in the mask will be drawn;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2896
		       0-bit mask pixels lead to transparent pixels.
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2897
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2898
     For depth8 masks: (future):
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2899
		       each pixel specifies the alpha value (0..255),
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2900
		       which specifies the transparency of that pixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2901
		       0 means completely transparent, 255 means completely
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2902
		       opaque. The 1-plane mask is a special case of this,
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2903
		       interpreting a 0 as a 0 alpha value and 1's as an
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2904
		       alpha value of 255."
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2905
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2906
    mask := anotherImage.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2907
    maskedPixelsAre0 := false.
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2908
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2909
    "Created: 27.6.1996 / 17:45:22 / cg"
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2910
    "Modified: 12.4.1997 / 12:04:39 / cg"
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2911
!
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2912
1587
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2913
maskedPixelsAre0
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2914
    "return true if masked pixels have been cleared to zero"
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2915
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2916
    ^ maskedPixelsAre0 == true
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2917
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2918
    "Modified: / 22.8.1998 / 11:27:22 / cg"
1587
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2919
!
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2920
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2921
maskedPixelsAre0:aBoolean
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2922
    "set/clear the flag which states if masked pixels
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2923
     have been set to zero. Knowing this to be true allows
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2924
     faster drawing of the image later; (however, not setting
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2925
     it will still produce correct output).
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2926
     This flag is typically set by image readers."
1587
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2927
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2928
    maskedPixelsAre0 := aBoolean
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2929
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2930
    "Modified: 12.4.1997 / 12:08:42 / cg"
1587
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2931
!
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2932
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2933
monochromeId
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2934
    "return the id of the monochrome image on the device.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2935
     Return nil, if the image is unassigned."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2936
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2937
    monoDeviceForm isNil ifTrue:[^ nil].
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2938
    ^ monoDeviceForm id
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2939
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2940
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2941
palette
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2942
    "return the colormap; ST-80 compatibility"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2943
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2944
    ^ colorMap
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2945
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2946
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2947
palette:aColormap
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2948
    "set the colormap; ST-80 compatibility"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2949
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  2950
    self colorMap:aColormap
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2951
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2952
    "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
  2953
    "Modified: 8.6.1996 / 09:54:02 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2954
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2955
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2956
photometric
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  2957
    "return the photometric, a symbol such as #palette, #rgb etc.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  2958
     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
  2959
     Much better would be to always have some (possibly fake and virtual) colormap around, and ask that one.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  2960
     However, in the meantime, many other classes depend on that, so that it should be kept as an API 
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  2961
     - 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
  2962
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2963
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2964
    ^ photometric
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2965
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2966
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2967
samplesPerPixel
6840
3dee5e952e94 class: Image
Stefan Vogel <sv@exept.de>
parents: 6831
diff changeset
  2968
    "return the number of samples per pixel in the image."
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2969
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2970
    samplesPerPixel notNil ifTrue:[^ samplesPerPixel].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2971
    ^ 1
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2972
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2973
    "Modified: 10.6.1996 / 18:03:30 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2974
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2975
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2976
setColorMap:aColorMap
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2977
    (aColorMap isNil or:[aColorMap isKindOf:Colormap]) ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2978
	colorMap := MappedPalette withColors:aColorMap
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2979
    ] ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2980
	colorMap := aColorMap
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2981
    ]
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2982
!
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2983
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2984
width
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2985
    "return the width of the image"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2986
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2987
    ^ width
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2988
! !
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2989
3263
bd92a12c9316 category changes
Claus Gittinger <cg@exept.de>
parents: 3259
diff changeset
  2990
!Image methodsFor:'accessing-pixels'!
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2991
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2992
at:aPoint
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2993
    "WARNING: for now, this returns a pixels color
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2994
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2995
     In the future, this will return a pixel value (ST-80 compatibility)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2996
     Use #colorAt: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2997
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2998
     retrieve the pixel at aPoint; return a color.
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2999
     Pixels start at 0@0 for upper left pixel, end at
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3000
     (width-1)@(height-1) for lower right pixel.
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3001
     You should not use this method for image-processing, its
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3002
     very slow ...
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3003
     (it is meant to access individual pixels - for example, in a bitmap editor)"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3004
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  3005
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  3006
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
  3007
    self obsoleteMethodWarning:'Image [warning]: the Image>>at: will change semantics soon; use #colorAt:'.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3008
    ^ self colorAtX:(aPoint x) y:(aPoint y)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
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:10:17 / 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:33:52 / stefan"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3012
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  3013
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3014
at:aPoint put:aColor
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3015
    "WARNING: for now, this expects a pixels color
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3016
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3017
     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
  3018
     Use #colorAt:put: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3019
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3020
     set the pixel at aPoint to aColor.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3021
     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
  3022
     (width-1)@(height-1) for lower right pixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3023
     You should not use this method for image-processing, its
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3024
     very slow ...
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3025
     (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
  3026
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  3027
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  3028
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
  3029
    self obsoleteMethodWarning:'Image [warning]: the Image>>at:put: will change semantics soon; use #colorAt:put:'.
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  3030
    ^ self colorAtX:aPoint x y:aPoint y put:aColor
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  3031
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
  3032
    "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
  3033
    "Modified: / 9.1.1998 / 20:34:15 / stefan"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3034
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3035
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3036
atImageAndMask:aPoint put:aColorOrPixelOrNil
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  3037
    "set the pixel at x/y to aColor.
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3038
     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
  3039
     otherwise to 1. Nil is treated like noColor.
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  3040
     (used by the bitmap editor)"
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  3041
2523
4c197af8cc50 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2502
diff changeset
  3042
    |maskVal|
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3043
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3044
    (aColorOrPixelOrNil notNil and:[aColorOrPixelOrNil ~= Color noColor]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3045
	maskVal := 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3046
	aColorOrPixelOrNil isInteger ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3047
	    self pixelAt:aPoint put:aColorOrPixelOrNil.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3048
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3049
	    self colorAt:aPoint put:aColorOrPixelOrNil
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3050
	]
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3051
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3052
	maskVal := 0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3053
	self pixelAt:aPoint put:0.
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3054
    ].
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3055
    mask notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3056
	mask pixelAt:aPoint put:maskVal
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3057
    ].
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3058
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3059
    "Modified: / 30.9.1998 / 22:42:44 / cg"
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3060
!
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3061
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3062
atImageAndMask:aPoint putValue:aPixelValueOrNil
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3063
    "set the pixel at x/y to aColor.
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3064
     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
  3065
     otherwise to 1. (used by the bitmap editor)"
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3066
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3067
    |pixVal maskVal|
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3068
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3069
    aPixelValueOrNil notNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  3070
	pixVal := aPixelValueOrNil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  3071
	maskVal := 1.
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3072
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  3073
	pixVal := 0.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  3074
	maskVal := 0.
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3075
    ].
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3076
    mask notNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  3077
	mask pixelAt:aPoint put:maskVal
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3078
    ].
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3079
    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
  3080
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3081
    "Modified: / 30.9.1998 / 22:42:44 / cg"
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  3082
!
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  3083
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3084
atPoint:aPoint
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3085
    "ST-80 compatibility: return the pixelValue at:aPoint."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3086
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3087
    ^ self pixelAtX:aPoint x y:aPoint y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3088
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3089
    "Modified: 24.4.1997 / 16:18:44 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3090
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3091
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3092
atPoint:aPoint put:aPixelValue
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3093
    "ST-80 compatibility: set the pixelValue at:aPoint."
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3094
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3095
    ^ self pixelAtX:aPoint x y:aPoint y put:aPixelValue
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3096
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3097
    "Modified: 24.4.1997 / 17:17:59 / cg"
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3098
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3099
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3100
atX:x y:y
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3101
    "WARNING: for now, this returns a pixels color
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3102
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3103
     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
  3104
     Use #colorAt: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3105
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3106
     Retrieve a pixel at x/y; return a color.
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3107
     Pixels start at 0@0 for upper left pixel, end at
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3108
     (width-1)@(height-1) for lower right pixel.
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3109
     You should not use this method for image-processing, its
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3110
     very slow ...
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3111
     (it is meant to access individual pixels - for example, in a bitmap editor)"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3112
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  3113
    'Image [warning]: the Image>>atX:y: will change semantics soon; use #colorAtX:y:' infoPrintCR.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3114
    ^ self colorAtX:x y:y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3115
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  3116
    "Modified: 21.6.1997 / 13:10:32 / cg"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3117
!
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3118
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3119
atX:x y:y put:aColor
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3120
    "WARNING: for now, this expects a pixels color
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3121
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3122
     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
  3123
     Use #colorAt:put: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3124
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3125
     set the pixel at x/y to aColor.
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3126
     Pixels start at 0@0 for the upper left pixel, end at
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3127
     (width-1)@(height-1) for the lower right pixel.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  3128
     This method checks if the color can be stored in the image.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  3129
     (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
  3130
     You should not use this method for image-processing, it is very slow ...
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3131
     (it is meant to access individual pixels - for example, in a bitmap editor)"
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3132
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  3133
    aColor isInteger ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3134
	'Image [warning]: the Image>>atX:y:put: will change semantics soon; use #colorAtX:y:put:' infoPrintCR.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3135
	^ self pixelAtX:x y:y put:aColor
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  3136
    ].
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3137
    ^ self colorAtX:x y:y put:aColor
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3138
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  3139
    "Modified: 21.6.1997 / 13:10:44 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3140
!
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3141
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3142
atX:x y:y putValue:aPixelValue
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3143
    "set the pixel at x/y to aPixelValue.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3144
     The interpretation of the pixelValue depends on the photometric
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3145
     and the colormap. (see also: Image>>atX:y:put:)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3146
     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
  3147
     (width-1) @ (height-1) for the lower right pixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3148
     You should not use this method for image-processing, its
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3149
     very slow ...
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3150
     (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
  3151
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  3152
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  3153
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3154
    self obsoleteMethodWarning:'use #pixelAtX:y:put:'.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3155
    ^ self pixelAtX:x y:y put:aPixelValue.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3156
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3157
    "Modified: 24.4.1997 / 17:15:45 / cg"
283
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
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3160
bits
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3161
    "return the raw image data (pixel data); 
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3162
     depending on the photometric, this has to be interpreted as monochrome, 
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3163
     greyscale, palette or rgb data.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3164
     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
  3165
     will store 2 pixels per byte, whereas a 2-bitPerPixel image will store
be0fa075e4c4 comment
Claus Gittinger <cg@exept.de>
parents: 4414
diff changeset
  3166
     4 pixels per byte."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3167
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3168
    bytes isNil ifTrue:[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3169
        pixelFunction notNil ifTrue:[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3170
            self createPixelStore.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3171
            0 to:height-1 do:[:y |
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3172
                0 to:width-1 do:[:x |
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3173
                    self pixelAtX:x y:y put:(pixelFunction value:x value:y)
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3174
                ].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3175
            ].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3176
        ].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3177
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3178
    ^ bytes
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3179
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3180
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3181
colorAt:aPoint
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3182
    "retrieve a pixel at x/y; return a color.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3183
     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
  3184
     (width-1)@(height-1) for lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3185
     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
  3186
     very slow ...
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3187
     (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
  3188
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3189
    ^ self colorAtX:(aPoint x) y:(aPoint y)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3190
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3191
    "Created: 24.4.1997 / 17:02:31 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3192
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3193
1962
8c7377d243f6 save mask in storeOn.
tz
parents: 1950
diff changeset
  3194
colorAt: aPoint put:aColor
8c7377d243f6 save mask in storeOn.
tz
parents: 1950
diff changeset
  3195
8c7377d243f6 save mask in storeOn.
tz
parents: 1950
diff changeset
  3196
    self colorAtX: aPoint x y: aPoint y put:aColor
8c7377d243f6 save mask in storeOn.
tz
parents: 1950
diff changeset
  3197
!
8c7377d243f6 save mask in storeOn.
tz
parents: 1950
diff changeset
  3198
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3199
colorAtX:x y:y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3200
    "retrieve a pixel at x/y; return a color.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3201
     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
  3202
     (width-1)@(height-1) for lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3203
     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
  3204
     very slow ...
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3205
     (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
  3206
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3207
    |pixel|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3208
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3209
    pixel := self pixelAtX:x y:y.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3210
    ^ self colorFromValue:pixel
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3211
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3212
    "Modified: 24.4.1997 / 16:18:53 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3213
    "Created: 24.4.1997 / 17:00:52 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3214
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3215
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3216
colorAtX:x y:y put:aColor
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3217
    "set the pixel at x/y to aColor.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3218
     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
  3219
     (width-1)@(height-1) for the lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3220
     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
  3221
     (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
  3222
     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
  3223
     (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
  3224
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3225
    |pixel|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3226
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3227
    pixel := self valueFromColor:aColor.
2182
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3228
    pixel isNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3229
	^ UnrepresentableColorSignal raiseErrorString:'cannot store color - not in colormap'.
2182
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3230
    ].
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3231
    self pixelAtX:x y:y put:pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3232
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3233
    "Modified: 24.4.1997 / 17:36:20 / cg"
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
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3236
data
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3237
    "for backward compatibility - will vanish"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3238
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  3239
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  3240
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3241
    self obsoleteMethodWarning:'use #bits'.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3242
    ^ self bits
1660
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
    "Modified: 24.4.1997 / 17:37:57 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3245
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3246
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3247
data:aByteArray
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3248
    "for backward compatibility - will vanish"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3249
4175
a9e65365e590 Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 4173
diff changeset
  3250
    <resource:#obsolete>
3966
950a2db201c7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3964
diff changeset
  3251
    self obsoleteMethodWarning:'use #bits:'.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3252
    self bits:aByteArray
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3253
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3254
    "Modified: 24.4.1997 / 17:38:18 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3255
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3256
2182
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3257
maskAt:aPoint
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3258
    "retrieve the maskValue at aPoint - an integer number which is
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3259
     0 for masked pixels (invisible), 1 for unmasked (visible).
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3260
     For images without mask, 1 is returned for all pixels."
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3261
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3262
    ^ self maskAtX:aPoint x y:aPoint y
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3263
!
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3264
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3265
maskAt:aPoint put:maskValue
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3266
    "set the maskValue at aPoint - an integer number which is
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3267
     0 for masked pixels (invisible), 1 for unmasked (visible)."
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3268
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3269
    ^ self maskAtX:aPoint x y:aPoint y put:maskValue
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3270
!
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3271
2182
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3272
maskAtX:x y:y
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3273
    "retrieve the maskValue at aPoint - an integer number which is
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3274
     0 for masked pixels (invisible), 1 for unmasked (visible).
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3275
     For images without mask, 1 is returned for all pixels."
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3276
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3277
    mask isNil ifTrue:[^ 1].
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3278
    ^ mask pixelAtX:x y:y
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3279
!
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3280
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3281
maskAtX:x y:y put:maskValue
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3282
    "set the maskValue at aPoint - an integer number which is
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3283
     0 for masked pixels (invisible), 1 for unmasked (visible)."
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3284
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3285
    mask isNil ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3286
	maskValue == 1 ifTrue:[^ self].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3287
	self error:'image has no mask'.
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3288
    ].
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3289
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3290
    ^ mask pixelAtX:x y:y put:maskValue
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3291
!
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3292
2205
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3293
pixelAt:aPoint
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3294
    "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
  3295
     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
  3296
     (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
  3297
     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
  3298
     very slow ...
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3299
     (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
  3300
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3301
    ^ 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
  3302
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3303
    "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
  3304
!
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3305
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3306
pixelAt:aPoint put:aPixelValue
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3307
    "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
  3308
     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
  3309
     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
  3310
     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
  3311
     (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
  3312
     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
  3313
     very slow ...
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3314
     (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
  3315
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3316
    ^ 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
  3317
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3318
    "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
  3319
!
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3320
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3321
pixelAtX:x y:y
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3322
    "retrieve the pixelValue at aPoint; return an integer number.
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3323
     Pixels start at 0/0 for upper left pixel, and end at
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3324
     width-1@height-1 for lower right pixel.
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3325
     The returned numbers interpretation depends on the photometric
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3326
     and the colormap. (see also Image>>at: and Image>>atX:y:)
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3327
     You should not use this method for image-processing of
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3328
     big images, its very slow ...
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3329
     (it is meant to access individual pixels - for example, in a bitmap editor)"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3330
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3331
    pixelFunction notNil ifTrue:[^ pixelFunction value:x value:y].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3332
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3333
    ^ self subclassResponsibility
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3334
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3335
    "Created: 24.4.1997 / 16:06:56 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3336
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3337
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3338
pixelAtX:x y:y put:aPixelValue
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3339
    "set the pixel at x/y to aPixelValue.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3340
     The interpretation of the pixelValue depends on the photometric
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3341
     and the colormap. (see also: Image>>atX:y:put:)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3342
     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
  3343
     (width-1) @ (height-1) for the lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3344
     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
  3345
     very slow ...
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3346
     (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
  3347
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3348
    ^ self subclassResponsibility
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3349
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3350
    "Created: 24.4.1997 / 17:05:11 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3351
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3352
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3353
rgbValueAt:aPoint
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3354
    "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
  3355
     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
  3356
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3357
    ^ self rgbValueAtX:(aPoint x) y:(aPoint y)
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3358
!
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3359
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3360
rgbValueAtX:x y:y
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3361
    "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
  3362
     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
  3363
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3364
    |pixel|
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3365
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3366
    pixel := self pixelAtX:x y:y.
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3367
    ^ self rgbFromValue:pixel
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3368
!
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3369
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  3370
rgbValueAtX:x y:y put:newRGBValue
4858
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3371
    |value|
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3372
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3373
    value := self valueFromRGB:newRGBValue.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3374
    self pixelAtX:x y:y put:value.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3375
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3376
    "Created: / 15-01-2008 / 15:56:10 / cg"
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3377
!
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3378
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3379
rowAt:y
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3380
    "retrieve an array filled with pixel values from
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3381
     a single row.
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3382
     Notice: row coordinate starts at 0.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3383
     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
  3384
     concrete image subclasses should redefine this for more performance."
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3385
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3386
    |pixelArray|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3387
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3388
    pixelArray := self pixelArraySpecies new:width.
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3389
    self rowAt:y into:pixelArray startingAt:1.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3390
    ^ pixelArray
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3391
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3392
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3393
     |i|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3394
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3395
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3396
     (i rowAt:0) inspect
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3397
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3398
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3399
     |i|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3400
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  3401
     i := Image fromFile:'libtool/bitmaps/SBrowser.xbm'.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3402
     (i rowAt:0) inspect
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3403
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3404
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3405
    "Modified: 24.4.1997 / 15:51:24 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3406
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3407
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3408
rowAt:y into:aPixelBuffer
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3409
    "fill aBuffer with pixel values retrieved from a single row.
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3410
     Notice: row coordinate starts at 0."
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3411
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3412
    ^ self rowAt:y into:aPixelBuffer startingAt:1
1660
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
    "Created: 24.4.1997 / 15:44:46 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3415
    "Modified: 24.4.1997 / 15:51:35 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3416
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3417
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3418
rowAt:y into:aPixelBuffer startingAt:startIndex
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3419
    "fill aBuffer with pixel values retrieved from a single row.
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3420
     Notice: row coordinate starts at 0.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3421
     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
  3422
     concrete image subclasses should redefine this for more performance."
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3423
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3424
    |w "{ Class: SmallInteger }"|
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
    w := width-1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3427
    0 to:w do:[:col |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  3428
	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
  3429
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3430
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3431
    "Created: 24.4.1997 / 15:05:21 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3432
    "Modified: 24.4.1997 / 16:52:43 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3433
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3434
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3435
rowAt:y putAll:pixelArray
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3436
    "store a single rows pixels from bits in the argument;
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3437
     Notice: row coordinate starts at 0.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3438
     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
  3439
     concrete image subclasses should redefine this for more performance."
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3440
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3441
    ^ self rowAt:y putAll:pixelArray 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
    "Modified: 24.4.1997 / 15:51:58 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3444
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3445
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3446
rowAt:y putAll:pixelArray startingAt:startIndex
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3447
    "store a single rows pixels from bits in the pixelArray argument;
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3448
     return the pixelArray.
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3449
     Notice: row coordinate starts at 0.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3450
     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
  3451
     concrete image subclasses should redefine this for more performance."
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3452
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3453
    |w "{ Class: SmallInteger }"|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3454
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3455
    w := width-1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3456
    0 to:w do:[:col |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  3457
	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
  3458
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3459
    ^ pixelArray
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
    "Modified: 24.4.1997 / 17:05:57 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3462
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3463
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3464
valueAt:aPoint
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3465
    "WARNING: for now, this returns a pixels value
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3466
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3467
     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
  3468
     Use #pixelAt: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3469
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3470
     Retrieve the pixelValue at aPoint; return an integer number.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3471
     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
  3472
     width-1@height-1 for lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3473
     The returned numbers interpretation depends on the photometric
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3474
     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
  3475
     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
  3476
     very slow ...
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3477
     (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
  3478
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  3479
    '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
  3480
    ^ self pixelAtX:aPoint x y:aPoint y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3481
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  3482
    "Modified: 21.6.1997 / 13:11:19 / cg"
1660
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
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3485
valueAtX:x y:y
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3486
    "WARNING: for now, this returns a pixels value
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3487
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3488
     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
  3489
     Use #pixelAt: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3490
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3491
     Retrieve the pixelValue at aPoint; return an integer number.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3492
     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
  3493
     width-1@height-1 for lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3494
     The returned numbers interpretation depends on the photometric
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3495
     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
  3496
     You should not use this method for image-processing of
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3497
     big images, its very slow ...
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3498
     (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
  3499
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  3500
    '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
  3501
    ^ self pixelAtX:x y:y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3502
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  3503
    "Modified: 21.6.1997 / 13:11:29 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3504
! !
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3505
3263
bd92a12c9316 category changes
Claus Gittinger <cg@exept.de>
parents: 3259
diff changeset
  3506
!Image methodsFor:'accessing-private'!
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3507
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3508
bits:aByteArray
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3509
    "set the raw data.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3510
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3511
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3512
     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
  3513
     existing image may confuse later pixel interpretation
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3514
     (it does not care for colormaps and/or cached device image flushing)."
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3515
6894
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3516
    |expectedSize d|
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3517
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3518
    bytes := aByteArray.
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3519
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3520
    "/ sanity check:
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3521
    "/ there seem to be images in some image-resource methods,
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3522
    "/ which were written with an invalid packed pixel string.
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3523
    "/ 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
  3524
    "/ If you encounter this halt,
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3525
    "/ please edit the image in the image editor and save it back.
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3526
    
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3527
    (width notNil and:[height notNil and:[(d := self depth) notNil]]) ifTrue:[
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3528
        (d <= 8) ifTrue:[
6896
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
  3529
            expectedSize := (self bytesPerRow * height).
6894
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3530
            bytes size < expectedSize ifTrue:[
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3531
                Smalltalk isSmalltalkDevelopmentSystem ifTrue:[
7222
matilk
parents: 7210
diff changeset
  3532
                    self breakPoint:#cg info:'invalid bytearray size'.
6894
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3533
                ].
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3534
                bytes := (ByteArray new:expectedSize) replaceFrom:1 with:bytes; yourself.
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3535
            ].
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3536
        ].
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3537
    ].
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
    "Modified: 23.4.1996 / 11:08:28 / cg"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3540
!
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3541
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3542
bits:aByteArrayArg colorMap:clrMapArg
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3543
    "set the raw data.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3544
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3545
     This interface is only to be used when initializing
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3546
     instances or by image readers. Calling for a change of an
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3547
     existing image may confuse later pixel interpretation
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3548
     (it does not care for colormaps and/or cached device image flushing)."
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3549
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3550
    self bits:aByteArrayArg.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3551
    self colorMap:clrMapArg.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3552
!
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3553
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3554
bits:aByteArrayArg colorMap:clrMapArg mask:maskArg
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3555
    "set the raw data.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3556
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3557
     This interface is only to be used when initializing
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3558
     instances or by image readers. Calling for a change of an
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3559
     existing image may confuse later pixel interpretation
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3560
     (it does not care for colormaps and/or cached device image flushing)."
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3561
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3562
    self bits:aByteArrayArg.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3563
    self colorMap:clrMapArg.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3564
    self mask:maskArg
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3565
!
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3566
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3567
bits:aByteArrayArg colorMapFromArray:clrMapArg
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3568
    "set the raw data.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3569
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3570
     This interface is only to be used when initializing
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3571
     instances or by image readers. Calling for a change of an
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3572
     existing image may confuse later pixel interpretation
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3573
     (it does not care for colormaps and/or cached device image flushing)."
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3574
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3575
    self bits:aByteArrayArg.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3576
    self colorMapFromArray:clrMapArg.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3577
!
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3578
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3579
bits:aByteArrayArg colorMapFromArray:clrMapArg mask:maskArg
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3580
    "set the raw data.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3581
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3582
     This interface is only to be used when initializing
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3583
     instances or by image readers. Calling for a change of an
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3584
     existing image may confuse later pixel interpretation
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3585
     (it does not care for colormaps and/or cached device image flushing)."
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3586
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3587
    self bits:aByteArrayArg.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3588
    self colorMapFromArray:clrMapArg.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3589
    self mask:maskArg
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3590
!
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3591
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3592
bits:aByteArrayArg mask:maskArg
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3593
    "set the raw data.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3594
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3595
     This interface is only to be used when initializing
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3596
     instances or by image readers. Calling for a change of an
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3597
     existing image may confuse later pixel interpretation
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3598
     (it does not care for colormaps and/or cached device image flushing)."
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3599
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3600
    self bits:aByteArrayArg.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3601
    self mask:maskArg
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3602
!
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3603
4115
0e783379a6b0 Use ByteArray for bitsPerSample (255 should be enough ;-)
Stefan Vogel <sv@exept.de>
parents: 4109
diff changeset
  3604
bitsPerSample:aCollection
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3605
    "set the number of bits per sample.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3606
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3607
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3608
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3609
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3610
6862
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3611
    "/ the following is a trick to get shared Immutable instances, at least for the
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3612
    "/ most common cases. Prevents writers to do what is described above.
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3613
    "/ Just an experiment...
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3614
    aCollection = #( 8 8 8 ) ifTrue:[
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3615
        bitsPerSample := #( 8 8 8 )
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3616
    ] ifFalse:[
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3617
        aCollection = #( 8 ) ifTrue:[
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3618
            bitsPerSample := #( 8 )
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3619
        ] ifFalse:[
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3620
            bitsPerSample := aCollection
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3621
        ].
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3622
    ].
6899
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  3623
    samplesPerPixel isNil ifTrue:[
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  3624
        samplesPerPixel := bitsPerSample size.
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  3625
    ].
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3626
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3627
    "Modified: 23.4.1996 / 11:08:31 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3628
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3629
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3630
depth:d
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3631
    "set the depth of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3632
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3633
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3634
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3635
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3636
1362
454d644f6ff7 set depth & bitsPerPixel for ST-80 compatibility.
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
  3637
    depth := self depth.
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
  3638
    "/ bitsPerPixel := d.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3639
    d == 24 ifTrue:[
6862
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3640
        samplesPerPixel := 3.
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3641
        bitsPerSample := #(8 8 8)
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3642
    ] ifFalse:[
6862
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3643
        d == 32 ifTrue:[
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3644
            samplesPerPixel := 4.
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3645
            bitsPerSample := #(8 8 8 8)
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3646
        ] ifFalse:[
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3647
            d == 16 ifTrue:[
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3648
                samplesPerPixel := 3.
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
  3649
                bitsPerSample := #(5 5 5).
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
  3650
                "/ bitsPerPixel := 15.
6862
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3651
            ] ifFalse:[
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3652
                samplesPerPixel := 1.
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3653
                bitsPerSample := ByteArray with:d
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3654
            ]
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3655
        ]
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3656
    ]
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3657
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  3658
    "Modified: / 27-05-2007 / 16:59:47 / cg"
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
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3661
extent:anExtent
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3662
    "set the images extent.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3663
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3664
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3665
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3666
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3667
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3668
    width := anExtent x.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3669
    height := anExtent y
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3670
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3671
    "Modified: 23.4.1996 / 11:08:38 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3672
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3673
5326
0443d8649cac *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5319
diff changeset
  3674
hasAlphaChannel
0443d8649cac *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5319
diff changeset
  3675
    ^ false
0443d8649cac *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5319
diff changeset
  3676
!
0443d8649cac *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5319
diff changeset
  3677
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3678
height:aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3679
    "set the height of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3680
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3681
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3682
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3683
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3684
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3685
    height := aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3686
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3687
    "Modified: 23.4.1996 / 11:08:40 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3688
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3689
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3690
photometric:aSymbol
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3691
    "set the photometric interpretation of the pixel values.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3692
     The argument, aSymbol is one of:
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3693
	#blackIs0, #whiteIs0, #palette, #rgb
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3694
     See TIFF documentation, from which the photometric concept is borrowed.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3695
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3696
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3697
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3698
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3699
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3700
    |b|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3701
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3702
    photometric := aSymbol.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3703
    bitsPerSample isNil ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3704
	photometric == #rgb ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3705
	    b := self class imageDepth // 3.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3706
	    bitsPerSample := ByteArray with:b with:b with:b
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3707
	] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3708
	    bitsPerSample := ByteArray with:(self class imageDepth)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3709
	].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3710
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3711
    samplesPerPixel isNil ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3712
	photometric == #rgb ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3713
	    samplesPerPixel := 3
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3714
	] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3715
	    samplesPerPixel := 1
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3716
	]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3717
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3718
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3719
    "Modified: 10.6.1996 / 18:21:29 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3720
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3721
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3722
samplesPerPixel:aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3723
    "set the array of samples per pixel.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3724
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3725
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3726
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3727
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3728
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3729
    samplesPerPixel := aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3730
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3731
    "Modified: 23.4.1996 / 11:08:45 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3732
!
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3733
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3734
width:aNumber
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3735
    "set the width of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3736
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3737
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3738
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3739
     existing image may confuse later pixel interpretation."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3740
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3741
    width := aNumber
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3742
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3743
    "Modified: 23.4.1996 / 11:08:48 / cg"
100
1b0b86c77397 co !!:*
claus
parents: 89
diff changeset
  3744
!
1b0b86c77397 co !!:*
claus
parents: 89
diff changeset
  3745
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3746
width:w height:h
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3747
    "set the width and height of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3748
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3749
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3750
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3751
     existing image may confuse later pixel interpretation."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3752
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3753
    width := w.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3754
    height := h
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3755
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3756
    "Modified: 23.4.1996 / 11:08:53 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3757
!
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3758
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3759
width:w height:h depth:d
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3760
    "set the width, height and depth of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3761
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3762
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3763
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3764
     existing image may confuse later pixel interpretation."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3765
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3766
    width := w.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3767
    height := h.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3768
    self depth:d.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3769
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3770
    "Modified: 23.4.1996 / 11:08:56 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  3771
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  3772
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3773
width:w height:h depth:d fromArray:bits
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3774
    "set the width, height, depth and pixels of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3775
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3776
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3777
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3778
     existing image may confuse later pixel interpretation."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3779
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3780
    width := w.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3781
    height := h.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3782
    self depth:d.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3783
    self bits:bits
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3784
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3785
    "Modified: 23.4.1996 / 11:08:59 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3786
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3787
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3788
width:w height:h depth:d palette:aColormap
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3789
    "set the width, height and depth of the image.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3790
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3791
     This interface is only to be used when initializing
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3792
     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
  3793
     existing image may confuse later pixel interpretation."
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3794
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3795
    width := w.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3796
    height := h.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3797
    self depth:d.
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  3798
    self setColorMap:aColormap.
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3799
    aColormap notNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  3800
	photometric := #palette
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  3801
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  3802
	photometric := #blackIs0
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  3803
    ].
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3804
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3805
    "Modified: 23.4.1996 / 11:08:56 / cg"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3806
    "Created: 6.3.1997 / 15:23:57 / cg"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3807
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3808
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3809
width:w height:h photometric:p
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3810
    "set the width, height and photometric of the image.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3811
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3812
     This interface is only to be used when initializing
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3813
     instances or by image readers. Calling for a change of an
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3814
     existing image may confuse later pixel interpretation."
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3815
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3816
    width := w.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3817
    height := h.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3818
    self photometric:p.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3819
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3820
    "Modified: 23.4.1996 / 11:08:56 / cg"
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3821
!
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3822
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3823
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
  3824
    "set all relevant internal state of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3825
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3826
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3827
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3828
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3829
894
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3830
    ^ self
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3831
	width:w
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3832
	height:h
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3833
	photometric:p
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3834
	samplesPerPixel:spp
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3835
	bitsPerSample:bps
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3836
	colorMap:cm
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3837
	bits:pixels
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3838
	mask:nil
894
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3839
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3840
    "Modified: 20.6.1996 / 17:10:24 / cg"
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3841
!
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3842
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3843
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
  3844
    "set all relevant internal state of the image.
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3845
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3846
     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
  3847
     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
  3848
     existing image may confuse later pixel interpretation."
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3849
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3850
    width := w.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3851
    height := h.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3852
    photometric := p.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3853
    samplesPerPixel := spp.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3854
    bitsPerSample := bps.
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  3855
    self setColorMap:cm.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3856
    self bits:pixels.
894
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3857
    mask := m.
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3858
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3859
    "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
  3860
    "Created: 20.6.1996 / 17:09:53 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3861
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
  3862
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  3863
2205
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3864
!Image methodsFor:'conversion helpers'!
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3865
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3866
rgbColormapFor:aDevice
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3867
    "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
  3868
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3869
    |nColors    "{ Class: SmallInteger }"
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3870
     scaleRed scaleGreen scaleBlue
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3871
     redShift   "{ Class: SmallInteger }"
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3872
     greenShift "{ Class: SmallInteger }"
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3873
     blueShift  "{ Class: SmallInteger }"
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3874
     colorValues|
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3875
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3876
    "/ 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
  3877
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3878
    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
  3879
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3880
    "/ 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
  3881
    "/ (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
  3882
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3883
    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
  3884
    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
  3885
    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
  3886
    redShift := aDevice shiftRed.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3887
    greenShift := aDevice shiftGreen.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3888
    blueShift := aDevice shiftBlue.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3889
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3890
    colorValues := Array uninitializedNew:nColors.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3891
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3892
    0 to:nColors-1 do:[:pixel |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3893
	|clr rv gv bv v "{ Class: SmallInteger }" |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3894
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3895
	clr := self colorFromValue:pixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3896
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3897
	rv := (clr red * scaleRed) rounded.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3898
	gv := (clr green * scaleGreen) rounded.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3899
	bv := (clr blue * scaleBlue) rounded.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3900
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3901
	v := rv bitShift:redShift.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3902
	v := v bitOr:(gv bitShift:greenShift).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3903
	v := v bitOr:(bv bitShift:blueShift).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3904
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3905
	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
  3906
"/ clr print. ' ' print.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3907
"/ 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
  3908
"/ ' -> ' print. v printNL.
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
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3911
    ^ colorValues
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3912
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3913
    "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
  3914
! !
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3915
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3916
!Image methodsFor:'converting'!
48194c26a46c Initial revision
claus
parents:
diff changeset
  3917
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3918
asBurkesDitheredMonochromeImage
837
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  3919
    "return a burkes dithered monochrome image from the receiver image.
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  3920
     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
  3921
     a floyd-steinberg dithered image.
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  3922
     Notice, that floyd-steinberg dithering is faster; both because less
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  3923
     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
  3924
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3925
    |monoBits|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3926
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3927
    monoBits := self burkesDitheredMonochromeBits.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3928
    ^ 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
  3929
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3930
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3931
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3932
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  3933
     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
  3934
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3935
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3936
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3937
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3938
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3939
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3940
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3941
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3942
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  3943
     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
  3944
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3945
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3946
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3947
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3948
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3949
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3950
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3951
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3952
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3953
     i := Depth4Image
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3954
	     width:4
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3955
	     height:4
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3956
	     fromArray:#[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3957
			    16r01 16r23
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3958
			    16r45 16r67
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3959
			    16r89 16rab
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3960
			    16rcd 16ref
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3961
			].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3962
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3963
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3964
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3965
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3966
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3967
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3968
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3969
    "Created: 10.6.1996 / 12:34:44 / cg"
837
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  3970
    "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
  3971
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3972
3157
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3973
asDitheredImageUsing:colors
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3974
    "return a dithered image from the picture,
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3975
     using colors in colors for dithering."
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3976
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3977
    ^ self asDitheredImageUsing:colors depth:self depth
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3978
!
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3979
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3980
asDitheredImageUsing:colors depth:d
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3981
    "return a dithered image from the picture,
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3982
     using colors in colors for dithering."
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3983
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3984
    |newBits|
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3985
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3986
    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
  3987
    newBits isNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  3988
	self error:'dithering failed'
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3905
diff changeset
  3989
    ].
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  3990
    ^ (self class newForDepth:d) extent:(self extent); depth:d; palette:colors; bits:newBits
3157
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3991
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3992
!
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3993
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3994
asErrorDitheredMonochromeImage
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3995
    "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
  3996
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3997
    DitherAlgorithm == #burkes ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3998
	^ self asBurkesDitheredMonochromeImage
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3999
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4000
    DitherAlgorithm == #stevensonArce ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4001
	^ self asStevensonArceDitheredMonochromeImage
809
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
    ^ self asFloydSteinbergDitheredMonochromeImage
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4004
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
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4007
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4008
     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
  4009
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4010
     i asErrorDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4011
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4012
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4013
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4014
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4015
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4016
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4017
     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
  4018
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4019
     i asErrorDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4020
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4021
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4022
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4023
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4024
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4025
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4026
     i := Depth4Image
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4027
	     width:4
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4028
	     height:4
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4029
	     fromArray:#[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4030
			    16r01 16r23
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4031
			    16r45 16r67
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4032
			    16r89 16rab
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4033
			    16rcd 16ref
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4034
			].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4035
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4036
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4037
     i asErrorDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4038
     i asOrderedDitheredMonochromeImage inspect.
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
    "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
  4042
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4043
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4044
asFloydSteinbergDitheredDepth8FormOn:aDevice colors:fixColors
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4045
    "return a floyd-steinberg dithered pseudoForm from the picture.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4046
     Use the colors in the fixColors array.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4047
     By passing the ditherColors as extra array, this method can
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4048
     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
  4049
     for example to create dithered Depth4Images from Depth8Images."
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4050
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4051
    |pseudoBits f deviceDepth map|
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4052
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4053
    deviceDepth := aDevice depth.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4054
    deviceDepth == 8 ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4055
	(aDevice supportedImageFormatForDepth:8) isNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4056
	    ^ nil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4057
	]
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4058
    ].
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4059
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4060
    pseudoBits := self floydSteinbergDitheredDepth8BitsColors:fixColors.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4061
    pseudoBits isNil ifTrue:[^ nil].
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4062
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4063
    f := Form width:width height:height depth:deviceDepth onDevice:aDevice.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4064
    f isNil ifTrue:[^ nil].
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4065
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4066
    "/
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4067
    "/ have to create a funny colorMap, where
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4068
    "/ color at:index == color colorId:index
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4069
    "/
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4070
    map := Array new:256.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4071
    fixColors do:[:clr |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4072
	map at:clr colorId + 1 put:clr
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4073
    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4074
    f colorMap:map.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4075
    f initGC.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4076
    f bits:pseudoBits.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4077
    aDevice
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4078
	drawBits:pseudoBits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4079
	bitsPerPixel:8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4080
	depth:deviceDepth
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4081
	padding:8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4082
	width:width height:height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4083
	x:0 y:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4084
	into:(f id) x:0 y:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4085
	width:width height:height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4086
	with:(f gcId).
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4087
    ^ f
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4088
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4089
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4090
     example:
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4091
	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
  4092
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4093
     |img8 reducedImg8 img4 map form|
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4094
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4095
     map := #(
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4096
		  (0     0   0)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4097
		  (0     0 100)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4098
		  (0    50   0)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4099
		  (0    50 100)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4100
		  (0   100   0)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4101
		  (0   100 100)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4102
		  (100   0   0)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4103
		  (100   0 100)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4104
		  (100  50   0)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4105
		  (100  50 100)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4106
		  (100 100   0)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4107
		  (100 100 100)) collect:[:rgb | (Color red:(rgb at:1)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4108
						      green:(rgb at:2)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4109
						       blue:(rgb at:3)) onDevice:Display].
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4110
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4111
     img8 := Image fromFile:'goodies/bitmaps/bf.im8'.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4112
     form := img8 paletteImageAsDitheredPseudoFormOn:Display
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4113
		      colors:map
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4114
			nRed:2
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4115
		      nGreen:3
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4116
		       nBlue:2.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4117
     img8 := Depth8Image fromForm:form.    'dithered version of original image'.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4118
     img4 := Depth4Image fromImage:img8.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4119
    "
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4120
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4121
    "Modified: 14.6.1996 / 16:52:34 / cg"
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4122
    "Created: 23.6.1997 / 15:25:37 / cg"
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4123
!
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4124
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4125
asFloydSteinbergDitheredDepth8FormOn:aDevice colors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4126
    "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
  4127
     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
  4128
     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
  4129
     Color class.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4130
     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
  4131
     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
  4132
     for example to create dithered Depth4Images from Depth8Images."
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4133
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4134
    |pseudoBits f deviceDepth map|
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4135
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4136
    deviceDepth := aDevice depth.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4137
    deviceDepth == 8 ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4138
	(aDevice supportedImageFormatForDepth:8) isNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4139
	    ^ nil
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4140
	]
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4141
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4142
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4143
    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
  4144
    pseudoBits isNil ifTrue:[^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4145
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4146
    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
  4147
    f isNil ifTrue:[^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4148
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4149
    "/
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4150
    "/ have to create a funny colorMap, where
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4151
    "/ color at:index == color colorId:index
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4152
    "/
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4153
    map := Array new:256.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4154
    fixColors do:[:clr |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4155
	map at:clr colorId + 1 put:clr
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4156
    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4157
    f colorMap:map.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4158
    f initGC.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4159
    f bits:pseudoBits.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4160
    aDevice
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4161
	drawBits:pseudoBits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4162
	bitsPerPixel:8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4163
	depth:deviceDepth
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4164
	padding:8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4165
	width:width height:height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4166
	x:0 y:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4167
	into:(f id) x:0 y:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4168
	width:width height:height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4169
	with:(f gcId).
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4170
    ^ f
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4171
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4172
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4173
     example:
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4174
	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
  4175
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4176
     |img8 reducedImg8 img4 map form|
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4177
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4178
     map := #(
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4179
		  (0     0   0)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4180
		  (0     0 100)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4181
		  (0    50   0)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4182
		  (0    50 100)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4183
		  (0   100   0)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4184
		  (0   100 100)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4185
		  (100   0   0)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4186
		  (100   0 100)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4187
		  (100  50   0)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4188
		  (100  50 100)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4189
		  (100 100   0)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4190
		  (100 100 100)) collect:[:rgb | (Color red:(rgb at:1)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4191
						      green:(rgb at:2)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4192
						       blue:(rgb at:3)) onDevice:Display].
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4193
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4194
     img8 := Image fromFile:'goodies/bitmaps/bf.im8'.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4195
     form := img8 paletteImageAsDitheredPseudoFormOn:Display
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4196
		      colors:map
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4197
			nRed:2
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4198
		      nGreen:3
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4199
		       nBlue:2.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4200
     img8 := Depth8Image fromForm:form.    'dithered version of original image'.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4201
     img4 := Depth4Image fromImage:img8.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4202
    "
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4203
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4204
    "Modified: 14.6.1996 / 16:52:34 / cg"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4205
!
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4206
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4207
asFloydSteinbergDitheredGrayFormOn:aDevice
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4208
    "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
  4209
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4210
    |depth bits|
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4211
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4212
    depth := aDevice depth.
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4213
    (depth == 1
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4214
    or:[aDevice hasGrayscales not]) ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4215
	"/ for monochrome, there is specialized
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4216
	"/ monochrome dither code available
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4217
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4218
	bits := self floydSteinbergDitheredMonochromeBits.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4219
    ] ifFalse:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4220
	bits := self floydSteinbergDitheredGrayBitsDepth:depth.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4221
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4222
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4223
    ^ 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
  4224
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4225
    "
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4226
     |i|
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4227
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4228
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4229
     (i asFloydSteinbergDitheredGrayFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4230
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4231
841
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  4232
    "
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4233
     |i|
841
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  4234
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  4235
     i := Image fromFile:'bitmaps/granite.tiff'.
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  4236
     (i asFloydSteinbergDitheredGrayFormOn:Display) inspect
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  4237
    "
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  4238
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4239
    "Created: 10.6.1996 / 14:11:39 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  4240
    "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
  4241
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4242
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4243
asFloydSteinbergDitheredGrayImageDepth:depth
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4244
    "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
  4245
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4246
    |ditheredBits|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4247
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4248
    (depth == 1) ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4249
	^ self asFloydSteinbergDitheredMonochromeImage
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4250
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4251
1779
34f9e24f330e method rename
Claus Gittinger <cg@exept.de>
parents: 1778
diff changeset
  4252
    ditheredBits := self floydSteinbergDitheredGrayBitsDepth:depth.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4253
    ^ (self class implementorForDepth:depth)
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4254
	width:width height:height fromArray:ditheredBits
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4255
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4256
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4257
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4258
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4259
     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
  4260
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4261
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4262
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4263
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4264
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4265
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4266
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4267
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4268
829
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4269
     i := Depth24Image width:4 height:1
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4270
	  fromArray:#[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4271
	    16rFF 16r00 16r00   16rFF 16r00 16r00  16rFF 16r00 16r00  16rFF 16r00 16r00
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4272
	    16rFF 16r00 16r00   16rFF 16r00 16r00  16rFF 16r00 16r00  16rFF 16r00 16r00
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4273
	    16rFF 16r00 16r00   16rFF 16r00 16r00  16rFF 16r00 16r00  16rFF 16r00 16r00
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4274
	    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
  4275
     i := i magnifiedBy:4@1.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4276
     i inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4277
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4278
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4279
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4280
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4281
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4282
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4283
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4284
     |i|
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4285
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4286
     i := Depth24Image width:4 height:6
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4287
	  fromArray:#[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4288
	    16r00 16r00 16r00   16r00 16r00 16r80  16r00 16r00 16rff  16r00 16r80 16r00
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4289
	    16r00 16r80 16r80   16r00 16rFF 16r00  16r00 16rFF 16r80  16r00 16rFF 16rFF
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4290
	    16r80 16r00 16r00   16r80 16r00 16r80  16r80 16r00 16rff  16r80 16r80 16r00
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4291
	    16r80 16r80 16r80   16r80 16rFF 16r00  16r80 16rFF 16r80  16r80 16rFF 16rFF
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4292
	    16rFF 16r00 16r00   16rFF 16r00 16r80  16rFF 16r00 16rff  16rFF 16r80 16r00
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4293
	    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
  4294
     i := i magnifiedBy:30.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4295
     i inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4296
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4297
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4298
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4299
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4300
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4301
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4302
     |i|
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4303
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4304
     i := Image fromFile:'granite.tiff'.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4305
     i inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4306
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4307
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4308
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4309
    "
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
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4312
     |i|
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4313
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4314
     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
  4315
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4316
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4317
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4318
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4319
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4320
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4321
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4322
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4323
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4324
     i := Depth4Image
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4325
	     width:4
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4326
	     height:4
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4327
	     fromArray:#[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4328
			    16r01 16r23
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4329
			    16r45 16r67
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4330
			    16r89 16rab
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4331
			    16rcd 16ref
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4332
			].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4333
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4334
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4335
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4336
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4337
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4338
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4339
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4340
    "Created: 10.6.1996 / 12:33:47 / cg"
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  4341
    "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
  4342
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4343
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4344
asFloydSteinbergDitheredMonochromeFormOn:aDevice
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4345
    "return a dithered moncohrome form from the receiver image."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4346
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4347
    |monoBits|
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4348
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4349
    monoBits := self floydSteinbergDitheredMonochromeBits.
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4350
    ^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4351
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4352
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4353
     |i f|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4354
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4355
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4356
     (i asFloydSteinbergDitheredMonochromeFormOn:Display) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4357
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4358
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4359
    "
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4360
     |i f|
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4361
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4362
     i := Depth2Image width:8 height:8
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4363
	  fromArray:#[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4364
			4r0000 4r0000
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4365
			4r0000 4r0000
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4366
			4r1111 4r1111
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4367
			4r1111 4r1111
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4368
			4r2222 4r2222
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4369
			4r2222 4r2222
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4370
			4r3333 4r3333
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4371
			4r3333 4r3333
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4372
		     ].
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4373
     (i asFloydSteinbergDitheredMonochromeFormOn:Display) inspect.
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4374
    "
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4375
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4376
    "Created: 10.6.1996 / 14:11:39 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  4377
    "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
  4378
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4379
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4380
asFloydSteinbergDitheredMonochromeImage
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4381
    "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
  4382
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4383
    |monoBits|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4384
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4385
    monoBits := self floydSteinbergDitheredMonochromeBits.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4386
    ^ 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
  4387
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4388
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4389
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4390
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4391
     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
  4392
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4393
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4394
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4395
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4396
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4397
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4398
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4399
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4400
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4401
     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
  4402
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4403
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4404
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4405
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4406
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4407
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4408
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4409
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4410
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4411
     i := Depth4Image
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4412
	     width:4
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4413
	     height:4
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4414
	     fromArray:#[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4415
			    16r01 16r23
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4416
			    16r45 16r67
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4417
			    16r89 16rab
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4418
			    16rcd 16ref
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4419
			].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4420
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4421
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4422
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4423
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4424
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4425
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4426
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4427
    "Created: 10.6.1996 / 12:33:47 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  4428
    "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
  4429
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4430
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4431
asFloydSteinbergDitheredPseudoFormUsing:colors on:aDevice
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4432
    "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
  4433
     using colors in colors for dithering."
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4434
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4435
    |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
  4436
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4437
    deviceDepth := aDevice depth.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4438
    has8BitImage := (deviceDepth == 8)
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4439
		    or:[ (aDevice supportedImageFormatForDepth:8) notNil ].
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4440
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  4441
    has8BitImage ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4442
	deviceDepth == 4 ifFalse:[^ nil].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4443
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4444
	pseudoBits8 := self nfloydSteinbergDitheredDepth8BitsColors:colors.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4445
	pseudoBits8 isNil ifTrue:[^ nil].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4446
	"/ convert to devices depth
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4447
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4448
	pseudoBits := ByteArray new:(width*4+7//8 * height).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4449
	pseudoBits8 compressPixels:4 width:width height:height into:pseudoBits mapping:nil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4450
	d := 4.
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  4451
    ] ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4452
	pseudoBits := self nfloydSteinbergDitheredDepth8BitsColors:colors.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4453
	pseudoBits isNil ifTrue:[^ nil].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4454
	d := 8.
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4455
    ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4456
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4457
    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
  4458
    f isNil ifTrue:[^ nil].
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4459
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4460
    "/
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4461
    "/ have to create a funny colorMap, where
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4462
    "/ color at:index == color colorId:index
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4463
    "/
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4464
    map := Array new:256 withAll:0.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4465
    colors do:[:clr |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4466
	clr notNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4467
	    map at:clr colorId + 1 put:clr
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4468
	]
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4469
    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4470
    f colorMap:map.
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4471
    f initGC.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4472
    f bits:pseudoBits.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4473
    aDevice
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4474
	drawBits:pseudoBits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4475
	bitsPerPixel:d
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4476
	depth:deviceDepth
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4477
	padding:8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4478
	width:width height:height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4479
	x:0 y:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4480
	into:(f id) x:0 y:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4481
	width:width height:height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4482
	with:(f gcId).
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4483
    ^ f
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4484
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4485
    "
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4486
     |i|
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4487
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4488
     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
  4489
     (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
  4490
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4491
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4492
     |i|
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4493
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4494
     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
  4495
     (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
  4496
    "
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4497
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4498
    "Created: 17.6.1996 / 12:13:35 / cg"
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  4499
    "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
  4500
!
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4501
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4502
asFormOn:aDevice
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4503
    "get a device form, with best possible approximation.
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4504
     remember it in case someone asks again."
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4505
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  4506
    |form visual|
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4507
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4508
    ((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ deviceForm].
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4509
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
  4510
    mask notNil ifTrue:[
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4511
        mask := mask onDevice:aDevice
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4512
    ].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4513
    bytes isNil ifTrue:[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4514
        pixelFunction notNil ifTrue:[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4515
            self computeBitsFromPixelFunction.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4516
        ]
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
  4517
    ].
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
  4518
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4519
    (aDevice depth == 1
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4520
    or:[aDevice hasGrayscales not]) ifTrue:[
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4521
        form := self asMonochromeFormOn:aDevice.
2212
ddc9cb6aeb73 more caching if device forms.
Claus Gittinger <cg@exept.de>
parents: 2206
diff changeset
  4522
    ] ifFalse:[
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4523
        ((visual := aDevice visualType) == #StaticGray) ifTrue:[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4524
            form := self asGrayFormOn:aDevice.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4525
        ] ifFalse:[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4526
            (visual == #PseudoColor
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4527
             or:[visual == #StaticColor]) ifTrue:[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4528
                form := self asPseudoFormQuickOn:aDevice.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4529
            ].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4530
        ]
2212
ddc9cb6aeb73 more caching if device forms.
Claus Gittinger <cg@exept.de>
parents: 2206
diff changeset
  4531
    ].
ddc9cb6aeb73 more caching if device forms.
Claus Gittinger <cg@exept.de>
parents: 2206
diff changeset
  4532
ddc9cb6aeb73 more caching if device forms.
Claus Gittinger <cg@exept.de>
parents: 2206
diff changeset
  4533
    form isNil ifTrue:[
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4534
        "/ kludge: repair a 'should not happen' situation...
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4535
        photometric isNil ifTrue:[ self repairPhotometric ].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4536
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4537
        (photometric == #palette) ifTrue:[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4538
            form := self paletteImageAsFormOn:aDevice
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4539
        ] ifFalse:[
7123
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
  4540
            (photometric == #rgb or:[photometric == #rgba or:[photometric == #argb]]) ifTrue:[
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4541
                form := self rgbImageAsFormOn:aDevice
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4542
            ] ifFalse:[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4543
                (photometric == #cmy or:[photometric == #cmyk]) ifTrue:[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4544
                    form := self rgbImageAsFormOn:aDevice
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4545
                ] ifFalse:[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4546
                    form := self greyImageAsFormOn:aDevice
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4547
                ]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4548
            ]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4549
        ].
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4550
    ].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4551
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4552
    (device isNil or:[aDevice == device]) ifTrue:[
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4553
        "remember this form in the receiver ..."
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4554
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4555
        form notNil ifTrue:[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4556
            form := form asImageForm.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4557
            deviceForm := form.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4558
            maskedPixelsAre0 := nil.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4559
            device isNil ifTrue:[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4560
                device := aDevice.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4561
                Lobby register:self
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4562
            ] ifFalse:[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4563
                Lobby registerChange:self
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4564
            ].
6496
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  4565
            mask notNil ifTrue:[
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  4566
                self clearMaskedPixels.
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  4567
            ].
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  4568
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4569
            "
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4570
             can save space, by not keeping the images data-bits
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4571
             twice (here and in the device form)
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4572
            "
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4573
            form forgetBits
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4574
        ]
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4575
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
  4576
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4577
    ^ form
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4578
4173
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  4579
    "
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  4580
     |i|
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  4581
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  4582
     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
  4583
     (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
  4584
    "
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  4585
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4586
    "Modified: / 06-06-2007 / 12:18:43 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4587
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4588
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4589
asGrayFormOn:aDevice
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4590
    "get a gray device form"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4591
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4592
    ^ self asGrayFormOn:aDevice dither:DitherAlgorithm.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4593
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4594
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4595
     |i|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4596
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4597
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4598
     (i asGrayFormOn:Display) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4599
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4600
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4601
    "Modified: 10.6.1996 / 17:39:30 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4602
    "Created: 10.6.1996 / 18:44:42 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4603
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4604
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4605
asGrayFormOn:aDevice dither:aDitherAlgorithm
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4606
    "get a greyscale device form, using aDitherAlgorithm."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4607
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4608
    |depth|
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4609
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4610
    depth := aDevice depth.
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4611
    (depth == 1
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4612
    or:[aDevice hasGrayscales not]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4613
	^ self asMonochromeFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4614
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4615
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4616
    (aDitherAlgorithm isNil
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4617
    or:[aDitherAlgorithm == #threshold]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4618
	^ self asThresholdGrayFormOn:aDevice
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
    (aDitherAlgorithm == #pattern
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4622
    or:[aDitherAlgorithm == #ordered]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4623
	^ self asOrderedDitheredGrayFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4624
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4625
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4626
    ^ self asFloydSteinbergDitheredGrayFormOn:aDevice.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4627
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4628
    "Created: 10.6.1996 / 18:42:01 / cg"
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  4629
    "Modified: 14.6.1996 / 15:17:28 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4630
!
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
asGrayImageDepth:depth
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4633
    "get a gray image from the receiver"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4634
6592
71b6996c8ed8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6586
diff changeset
  4635
    ((self colorMap notNil and:[depth <= 8 and:[depth >= self depth]])
5160
f465233332f1 fixed asGrayImage
sr
parents: 5143
diff changeset
  4636
    or:[ self depth >= 8 "do need for dither" ]) ifTrue:[
6592
71b6996c8ed8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6586
diff changeset
  4637
        ^ self copyWithColorMapProcessing:[:clr | Color brightness:(clr brightness)].
4417
5e5d9b696293 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  4638
    ].
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4639
    ^ self asGrayImageDepth:depth dither:DitherAlgorithm.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4640
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4641
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4642
     |i|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4643
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4644
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4645
     (i asGrayFormOn:Display) inspect.
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
    "Modified: 10.6.1996 / 17:39:30 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4649
    "Created: 10.6.1996 / 19:07:08 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4650
!
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
asGrayImageDepth:depth dither:aDitherAlgorithm
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4653
    "get a greyscale image, using aDitherAlgorithm."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4654
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4655
    (aDitherAlgorithm isNil
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4656
    or:[aDitherAlgorithm == #threshold]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4657
	^ self asThresholdGrayImageDepth:depth
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4658
    ].
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
    (aDitherAlgorithm == #pattern
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4661
    or:[aDitherAlgorithm == #ordered]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4662
	^ self asOrderedDitheredGrayImageDepth:depth
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4663
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4664
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4665
    ^ self asFloydSteinbergDitheredGrayImageDepth:depth
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4666
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4667
    "Created: 10.6.1996 / 19:08:21 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4668
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  4669
4423
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4670
asImageWithDepth:depth
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4671
    "return a new image with another depth. Notice that this
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4672
     may raise an error, if the depth is smaller than the receivers depths
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4673
     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
  4674
     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
  4675
     In the other case, use one of the dithering converters"
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4676
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4677
    |imageClass|
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4678
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4679
    imageClass := Image implementorForDepth:depth.
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4680
    ^ imageClass fromImage:self
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4681
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4682
    "
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4683
     |i|
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4684
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4685
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4686
     (i asImageWithDepth:24) inspect.
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4687
    "
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4688
    "
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4689
     |i|
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4690
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4691
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4692
     (i asImageWithDepth:4) inspect.
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4693
    "
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4694
!
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4695
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4696
asMonochromeFormOn:aDevice
48194c26a46c Initial revision
claus
parents:
diff changeset
  4697
    "get a monochrome device form"
48194c26a46c Initial revision
claus
parents:
diff changeset
  4698
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4699
    |form|
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4700
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4701
    ((aDevice == device) and:[monoDeviceForm notNil]) ifTrue:[^ monoDeviceForm].
4390
8d752f4cd9e2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  4702
    self depth == 1 ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4703
	((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ deviceForm].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4704
	^ self asFormOn:aDevice
1935
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
  4705
    ].
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4706
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4707
    form := self asMonochromeFormOn:aDevice dither:DitherAlgorithm.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4708
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4709
    (device isNil or:[aDevice == device]) ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4710
	"remember this form in the receiver ..."
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4711
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4712
	form notNil ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4713
	    form := form asImageForm.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4714
	    monoDeviceForm := form.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4715
	    device isNil ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4716
		device := aDevice.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4717
		Lobby register:self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4718
	    ] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4719
		Lobby registerChange:self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4720
	    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4721
	    "
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4722
	     can save space, by not keeping the images data-bits
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4723
	     twice (here and in the device form)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4724
	    "
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4725
	    form forgetBits
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4726
	]
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4727
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
  4728
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4729
    ^ form
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4730
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4731
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4732
     |i|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4733
4173
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  4734
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4735
     (i asMonochromeFormOn:Display) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4736
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4737
1935
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
  4738
    "Modified: 23.10.1997 / 00:44:59 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4739
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4740
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4741
asMonochromeFormOn:aDevice dither:aDitherAlgorithm
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4742
    "get a monochrome device form, using aDitherAlgorithm."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4743
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4744
    |monoBits|
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4745
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4746
    (aDitherAlgorithm isNil
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4747
    or:[aDitherAlgorithm == #threshold]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4748
	^ self asThresholdMonochromeFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4749
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4750
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4751
    aDitherAlgorithm == #burkes ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4752
	monoBits := self burkesDitheredMonochromeBits.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4753
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4754
	aDitherAlgorithm == #stevensonArce ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4755
	    monoBits := self stevensonArceDitheredMonochromeBits.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4756
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4757
	    (aDitherAlgorithm == #pattern
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4758
	    or:[aDitherAlgorithm == #ordered]) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4759
		^ self asOrderedDitheredGrayFormOn:aDevice.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4760
	    ] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4761
		^ self asFloydSteinbergDitheredMonochromeFormOn:aDevice.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4762
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4763
	]
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4764
    ].
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
    "/ make its pixel interpretation correct for the device
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4768
    "/
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4769
    ^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4770
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4771
    "Modified: 10.6.1996 / 20:18:05 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4772
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4773
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4774
asNearestPaintDepth8FormOn:aDevice colors:fixColors
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4775
    "return a nearest paint pseudoForm from the palette picture.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4776
     Use the colors in the fixColors array.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4777
     By passing the ditherColors as extra array, this method can
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4778
     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
  4779
     for example to create dithered Depth4Images from Depth8Images."
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4780
3914
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4781
    ^ 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
  4782
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4783
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4784
     example:
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4785
	color reduction from Depth8 to Depth4 can be done by:
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4786
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4787
     |img8 reducedImg8 img4 map form|
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4788
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4789
     map := #(
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4790
		  (0     0   0)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4791
		  (0     0 100)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4792
		  (0    50   0)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4793
		  (0    50 100)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4794
		  (0   100   0)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4795
		  (0   100 100)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4796
		  (100   0   0)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4797
		  (100   0 100)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4798
		  (100  50   0)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4799
		  (100  50 100)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4800
		  (100 100   0)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4801
		  (100 100 100)) collect:[:rgb | (Color red:(rgb at:1)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4802
						      green:(rgb at:2)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4803
						       blue:(rgb at:3)) onDevice:Display].
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4804
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4805
     img8 := Image fromFile:'goodies/bitmaps/claus.gif'.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4806
     form := img8 asNearestPaintDepth8FormOn:Display
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4807
		      colors:map
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4808
			nRed:2
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4809
		      nGreen:3
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4810
		       nBlue:2.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4811
     img8 := Depth8Image fromForm:form.    'dithered version of original image'.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4812
     img4 := Depth4Image fromImage:img8.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4813
    "
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4814
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4815
    "Modified: 17.6.1996 / 18:52:47 / cg"
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4816
    "Created: 23.6.1997 / 15:26:09 / cg"
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
asNearestPaintDepth8FormOn:aDevice colors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4820
    "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
  4821
     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
  4822
     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
  4823
     Color class.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4824
     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
  4825
     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
  4826
     for example to create dithered Depth4Images from Depth8Images."
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4827
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4828
    |pseudoBits f deviceDepth map|
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4829
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4830
    deviceDepth := aDevice depth.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4831
    deviceDepth == 8 ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4832
	(aDevice supportedImageFormatForDepth:8) isNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4833
	    ^ nil
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4834
	]
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4835
    ].
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4836
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4837
    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
  4838
    pseudoBits isNil ifTrue:[^ nil].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4839
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4840
    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
  4841
    f isNil ifTrue:[^ nil].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4842
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4843
    "/
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4844
    "/ have to create a funny colorMap, where
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4845
    "/ color at:index == color colorId:index
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4846
    "/
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4847
    map := Array new:256.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4848
    fixColors do:[:clr |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4849
	map at:clr colorId + 1 put:clr
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4850
    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4851
    f colorMap:map.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4852
    f initGC.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4853
    f bits:pseudoBits.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4854
    aDevice
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4855
	drawBits:pseudoBits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4856
	bitsPerPixel:8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4857
	depth:deviceDepth
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4858
	padding:8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4859
	width:width height:height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4860
	x:0 y:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4861
	into:(f id) x:0 y:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4862
	width:width height:height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4863
	with:(f gcId).
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4864
    ^ f
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4865
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4866
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4867
     example:
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4868
	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
  4869
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4870
     |img8 reducedImg8 img4 map form|
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4871
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4872
     map := #(
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4873
		  (0     0   0)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4874
		  (0     0 100)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4875
		  (0    50   0)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4876
		  (0    50 100)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4877
		  (0   100   0)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4878
		  (0   100 100)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4879
		  (100   0   0)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4880
		  (100   0 100)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4881
		  (100  50   0)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4882
		  (100  50 100)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4883
		  (100 100   0)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4884
		  (100 100 100)) collect:[:rgb | (Color red:(rgb at:1)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4885
						      green:(rgb at:2)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4886
						       blue:(rgb at:3)) onDevice:Display].
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4887
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4888
     img8 := Image fromFile:'goodies/bitmaps/claus.gif'.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4889
     form := img8 asNearestPaintDepth8FormOn:Display
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4890
		      colors:map
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4891
			nRed:2
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4892
		      nGreen:3
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4893
		       nBlue:2.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4894
     img8 := Depth8Image fromForm:form.    'dithered version of original image'.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4895
     img4 := Depth4Image fromImage:img8.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4896
    "
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4897
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4898
    "Created: 17.6.1996 / 18:47:46 / cg"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4899
    "Modified: 17.6.1996 / 18:52:47 / cg"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4900
!
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4901
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4902
asNearestPaintImageDepth:d colors:colors
3914
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4903
    "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
  4904
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4905
    |newBits|
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4906
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4907
    d ~~ 8 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  4908
	self error:'unsupported depth'
3914
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4909
    ].
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4910
    newBits := self nearestPaintDepth8BitsColors:colors nRed:nil nGreen:nil nBlue:nil.
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4911
    newBits isNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  4912
	self error:'conversion failed'
3914
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4913
    ].
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4914
    ^ (self class newForDepth:d) extent:(self extent); depth:d; palette:colors; bits:newBits
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4915
!
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4916
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4917
asOrderedDitheredGrayFormOn:aDevice
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4918
    "return a dithered depth-x grey form from the receiver image.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4919
     Uses an 8x8 dithermatrix."
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4920
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4921
    |depth bits|
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4922
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4923
    depth := aDevice depth.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4924
    (depth == 1
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4925
    or:[aDevice hasGrayscales not]) ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4926
	"/ for monochrome, there is highly specialized
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4927
	"/ monochrome dither code available
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4928
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4929
	^ self asOrderedDitheredMonochromeFormOn:aDevice
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4930
    ].
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4931
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4932
    bits := self
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4933
		orderedDitheredGrayBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4934
		ditherWidth:8
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4935
		depth:depth.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4936
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4937
    ^ self makeDeviceGrayPixmapOn:aDevice depth:depth fromArray:bits
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4938
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4939
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4940
     |i|
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4941
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4942
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4943
     (i asOrderedDitheredGrayFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4944
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4945
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  4946
    "Modified: 24.6.1997 / 22:19:30 / cg"
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4947
!
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4948
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4949
asOrderedDitheredGrayImageDepth:depth
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4950
    "return a dithered depth-x grey image from the receiver image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4951
     Uses an 8x8 dithermatrix."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4952
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4953
    |dither|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4954
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4955
    dither := self class orderedDitherMatrixOfSize:8.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4956
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4957
    (depth == 1) ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4958
	"/ for monochrome, there is highly specialized
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4959
	"/ monochrome dither code available
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4960
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4961
	^ Depth1Image
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4962
	    width:width
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4963
	    height:height
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4964
	    fromArray:(
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4965
		self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4966
		    orderedDitheredMonochromeBitsWithDitherMatrix:dither
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4967
		    ditherWidth:8)
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4968
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4969
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4970
    ^ (self class implementorForDepth:depth)
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4971
	width:width
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4972
	height:height
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4973
	fromArray:(
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4974
	    self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4975
		orderedDitheredGrayBitsWithDitherMatrix:dither
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4976
		ditherWidth:8
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4977
		depth:depth)
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4978
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4979
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4980
     |i i1 i2 i4 i8|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4981
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4982
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4983
     i1 := i asOrderedDitheredGrayImageDepth:1.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4984
     i1 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4985
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4986
     i2 := i asOrderedDitheredGrayImageDepth:2.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4987
     i2 inspect.
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
     i4 := i asOrderedDitheredGrayImageDepth:4.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4990
     i4 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4991
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4992
     i8 := i asOrderedDitheredGrayImageDepth:8.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4993
     i8 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4994
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4995
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4996
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4997
     |i i1 i2 i4 i8|
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4998
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4999
     i1 := i asOrderedDitheredGrayImageDepth:1.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5000
     i1 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5001
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5002
     i2 := i asOrderedDitheredGrayImageDepth:2.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5003
     i2 inspect.
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
     i4 := i asOrderedDitheredGrayImageDepth:4.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5006
     i4 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5007
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5008
     i8 := i asOrderedDitheredGrayImageDepth:8.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5009
     i8 inspect.
800
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  5010
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  5011
     i2 := i8 asOrderedDitheredGrayImageDepth:2.
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  5012
     i2 inspect.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5013
    "
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
    "Created: 7.6.1996 / 18:03:54 / cg"
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  5016
    "Modified: 24.6.1997 / 22:19:36 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5017
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5018
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5019
asOrderedDitheredMonochromeFormOn:aDevice
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5020
    "return a dithered monochrome form from the grey image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5021
     Uses a 4x4 dithermatrix."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5022
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5023
    "/ 4x4 seems a good comprimize between:
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5024
    "/    number of grey levels (8x8 is better)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5025
    "/    artifacts             (4x4 is better)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5026
    "/
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5027
    "/ could look at the image and decide upon the number of
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5028
    "/ distinct colors present. Use 8x8 for high-number,
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5029
    "/ 4x4 for small number of colors ...
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5030
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5031
    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5032
	asOrderedDitheredMonochromeFormOn:aDevice
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5033
	ditherMatrix:(self class orderedDitherMatrixOfSize:4)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5034
	ditherWidth:4
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5035
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5036
"/    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5037
"/        asOrderedDitheredMonochromeFormOn:aDevice
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5038
"/        ditherMatrix:(self class orderedDitherMatrixOfSize:8)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5039
"/        ditherWidth:8
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5040
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5041
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5042
     |i f|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5043
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5044
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5045
     f := i asOrderedDitheredMonochromeFormOn:Display.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5046
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5047
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5048
     |i f|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5049
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5050
     i := (Image fromFile:'goodies/bitmaps/winBitmaps/a11.ico') magnifiedBy:10.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5051
     f := i asOrderedDitheredMonochromeFormOn:Display.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5052
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5053
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5054
     |i f|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5055
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5056
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5057
     f := i asOrderedDitheredMonochromeFormOn:Display.
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
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5060
     |i f|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5061
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5062
     i := (Image fromFile:'doc/online/pictures/PasteButton.gif') magnifiedBy:10.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5063
     f := i asOrderedDitheredMonochromeFormOn:Display.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5064
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5065
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5066
     |i f|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5067
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5068
     i := (Image fromFile:'goodies/bitmaps/gifImages/blue-ball.gif') magnifiedBy:1.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5069
     f := i asOrderedDitheredMonochromeFormOn:Display.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5070
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5071
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5072
    "Created: 7.6.1996 / 14:52:32 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  5073
    "Modified: 17.4.1997 / 01:10:10 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5074
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5075
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5076
asOrderedDitheredMonochromeFormOn:aDevice ditherMatrix:ditherMatrix ditherWidth:dW
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5077
    "return a dithered monochrome form from the image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5078
     Uses the passed ditherMatrix and ditherWidth."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5079
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  5080
    |monoBits|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5081
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5082
    monoBits := self orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW.
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  5083
    ^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5084
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5085
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5086
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5087
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5088
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5089
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5090
     (i asOrderedDitheredMonochromeFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5091
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5092
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5093
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5094
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5095
     i := Image fromFile:'goodies/bitmaps/granite.tiff'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5096
     (i asOrderedDitheredMonochromeFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5097
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5098
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5099
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5100
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5101
     i := (Image fromFile:'goodies/bitmaps/PasteButton.tiff') magnifiedBy:10.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5102
     (i asOrderedDitheredMonochromeFormOn:Display) inspect
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5103
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5104
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5105
    "Created: 7.6.1996 / 14:51:42 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  5106
    "Modified: 17.4.1997 / 01:08:24 / cg"
798
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
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5109
asOrderedDitheredMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5110
    "return a dithered monochrome image from the receiver image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5111
     Uses a 4x4 dithermatrix."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5112
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5113
    "/ 4x4 seems a good comprimize between:
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5114
    "/    number of grey levels (8x8 is better)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5115
    "/    artifacts             (4x4 is better)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5116
    "/
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5117
    "/ could look at the image and decide upon the number of
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5118
    "/ distinct colors present. Use 8x8 for high-number,
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5119
    "/ 4x4 for small number of colors ...
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5120
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5121
    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5122
	asOrderedDitheredMonochromeImageWithDitherMatrix:(self class orderedDitherMatrixOfSize:4)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5123
	ditherWidth:4
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5124
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5125
"/    ^ self
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5126
"/        asOrderedDitheredMonochromeImageWithDitherMatrix:(self class orderedDitherMatrixOfSize:8)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5127
"/        ditherWidth:8
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5128
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5129
    "
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5130
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5131
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5132
     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
  5133
     i asOrderedDitheredMonochromeImage inspect
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5134
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5135
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5136
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5137
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5138
     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
  5139
     i asOrderedDitheredMonochromeImage inspect
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5140
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5141
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5142
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5143
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5144
     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
  5145
     i asOrderedDitheredMonochromeImage inspect
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5146
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5147
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5148
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5149
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5150
     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
  5151
     i asOrderedDitheredMonochromeImage inspect
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5152
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5153
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5154
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5155
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5156
     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
  5157
     i asOrderedDitheredMonochromeImage inspect
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5158
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5159
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5160
    "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
  5161
    "Modified: 10.6.1996 / 11:15:09 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5162
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5163
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5164
asOrderedDitheredMonochromeImageWithDitherMatrix:ditherMatrix ditherWidth:dW
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5165
    "return a dithered monochrome image from the receiver image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5166
     Uses the passed ditherMatrix and ditherWidth."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5167
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5168
    |monoBits|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5169
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5170
    monoBits := self orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5171
    ^ (Depth1Image width:width height:height fromArray:monoBits) photometric:#blackIs0
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5172
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5173
    "order-4 dither:
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5174
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5175
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5176
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5177
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5178
     i
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5179
	asOrderedDitheredMonochromeImageWithDitherMatrix:(Image orderedDitherMatrixOfSize:4)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5180
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5181
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5182
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5183
    "order-6 dither:
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5184
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5185
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5186
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5187
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5188
     i
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5189
	asOrderedDitheredMonochromeImageWithDitherMatrix:(Image orderedDitherMatrixOfSize:8)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5190
	ditherWidth:8
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5191
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5192
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5193
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5194
    "thresholding at:0.5 (all above 0.5 becomes white):
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
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5197
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5198
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5199
     i
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5200
	asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:8)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5201
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5202
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5203
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5204
    "thresholding at: 0.25 (all above 0.25 becomes white):
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
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5207
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5208
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5209
     i
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5210
	asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:3)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5211
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5212
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5213
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5214
    "thresholding at: 0.75 (all above 0.75 becomes white):
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5215
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5216
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5217
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5218
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5219
     i
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5220
	asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:11)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5221
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5222
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5223
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5224
    "Modified: 7.6.1996 / 17:23:47 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5225
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5226
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5227
asPseudoFormQuickOn:aDevice
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5228
    "return a pseudo-deviceForm from the image.
878
b99add8dc742 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 874
diff changeset
  5229
     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
  5230
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5231
    |f d
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5232
     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
  5233
     w            "{ Class: SmallInteger }"
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  5234
     h            "{ Class: SmallInteger }"
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  5235
     dDev         "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5236
     nClr         "{ Class: SmallInteger }"
2772
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  5237
     bytesPerLine "{ Class: SmallInteger }"
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  5238
     usedColors pix fmt bytes|
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5239
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5240
    d := self depth.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5241
    (d == 1
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5242
    or:[d == 2
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5243
    or:[d == 4
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5244
    or:[d == 8]]]) ifFalse:[^ nil].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5245
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  5246
    bytes := self bits.
2772
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  5247
    w := width.
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  5248
    h := height.
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  5249
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5250
    "/ 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
  5251
    "/ if the padding is not supported: fail
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5252
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5253
    dDev := aDevice depth.
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5254
    (bytesPerLine := dDev) == 8 ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5255
	bytesPerLine := (w * dDev + 7) // 8.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5256
    ].
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5257
2532
Claus Gittinger <cg@exept.de>
parents: 2530
diff changeset
  5258
    fmt := aDevice supportedImageFormatForDepth:dDev.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5259
    fmt isNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5260
	"/ cannot draw directly
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5261
	^ nil
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5262
    ].
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5263
    (bytesPerLine * 8) \\ (fmt at:#padding) == 0 ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5264
	"/ mhmh - ought to repad here;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5265
	"/ however, the nonQuick converter does it.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5266
	^ nil
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5267
    ].
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5268
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5269
    "/ see if all of the images colors are representable
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5270
    "/ on the device
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5271
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5272
    bits := self bitsPerPixel.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5273
    nClr := (1 bitShift:bits).
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5274
    cMap := Array new:nClr.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5275
    idMap := ByteArray new:nClr.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5276
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5277
    photometric == #palette ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5278
	nClr := nClr min:(colorMap size)
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5279
    ].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5280
878
b99add8dc742 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 874
diff changeset
  5281
    d == 8 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5282
	usedColors := bytes usedValues.    "gets us an array filled with used values"
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5283
	1 to:nClr do:[:pixel |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5284
	    (usedColors includes:(pixel - 1)) ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5285
		clr := Color black
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5286
	    ] ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5287
		clr := self colorFromValue:pixel-1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5288
		clr := clr exactOn:aDevice.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5289
		clr isNil ifTrue:[^ nil].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5290
	    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5291
	    (pix := clr colorId) isNil ifTrue:[^ nil].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5292
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5293
	    cMap at:(pixel) put:clr.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5294
	    idMap at:(pixel) put:pix.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5295
	].
878
b99add8dc742 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 874
diff changeset
  5296
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5297
	1 to:nClr do:[:pixel |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5298
	    clr := self colorFromValue:pixel-1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5299
	    clr := clr exactOn:aDevice.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5300
	    clr isNil ifTrue:[^ nil].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5301
	    (pix := clr colorId) isNil ifTrue:[^ nil].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5302
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5303
	    cMap at:(pixel) put:clr.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5304
	    idMap at:(pixel) put:pix.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5305
	].
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5306
    ].
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
    "/ got all colors; good - simply change depth & translate pixels
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5309
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5310
    (d == 8 and:[dDev == 8]) ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5311
	"/ only translate
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5312
	temp := ByteArray uninitializedNew:(w * h).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5313
	bytes expandPixels:8         "xlate only"
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5314
		    width:w
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5315
		   height:h
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5316
		     into:temp
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5317
		  mapping:idMap.
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5318
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5319
	"/ stupid: expandPixels can only handle any-to-8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5320
	"/ compressPixels can only handle 8-to-any
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5321
	"/ However, those methods are faster
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5322
	"/ - even if we convert twice.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5323
	"/ Therefore, convert first from myDepth to 8,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5324
	"/ then from 8 to the device depth.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5325
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5326
	d ~~ 8 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5327
	    temp8 := ByteArray uninitializedNew:(w * h).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5328
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5329
	    bytes expandPixels:d
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5330
			 width:w
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5331
			height:h
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5332
			  into:temp8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5333
		       mapping:idMap.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5334
	    idMap := nil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5335
	] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5336
	    temp8 := bytes.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5337
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5338
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5339
	dDev ~~ 8 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5340
	    temp := ByteArray uninitializedNew:(bytesPerLine * h).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5341
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5342
	    temp8 compressPixels:dDev
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5343
			 width:w
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5344
			height:h
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5345
			  into:temp
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5346
		       mapping:idMap.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5347
	] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5348
	    temp := temp8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5349
	].
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5350
    ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5351
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5352
    f := Form width:w height:h depth:dDev onDevice:aDevice.
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5353
    f isNil ifTrue:[^ nil].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5354
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5355
    f colorMap:cMap.
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5356
    f initGC.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5357
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5358
    aDevice
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5359
	drawBits:temp
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5360
	depth:dDev
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5361
	padding:8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5362
	width:w
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5363
	height:h
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5364
	x:0 y:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5365
	into:(f id) x:0 y:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5366
	width:w
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5367
	height:h
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5368
	with:(f gcId).
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5369
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5370
    ^ f
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5371
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5372
    "
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5373
     (
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5374
	(((Depth4Image
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5375
	     width:4
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5376
	     height:4
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5377
	     fromArray:#[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5378
			    16r01 16r23
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5379
			    16r45 16r67
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5380
			    16r89 16rab
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5381
			    16rcd 16ref
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5382
			]))
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5383
	       magnifiedBy:30
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5384
	 )
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5385
	  asPseudoFormQuickOn:Display
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5386
      ) inspect
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5387
     "
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5388
2113
c64f89f9ffba checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2102
diff changeset
  5389
    "Modified: / 7.5.1998 / 19:40:47 / cg"
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5390
!
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5391
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5392
asStevensonArceDitheredMonochromeImage
837
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  5393
    "return a stevenson-arce dithered monochrome image from the receiver image.
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  5394
     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
  5395
     a floyd-steinberg dithered image.
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  5396
     Notice, that floyd-steinberg dithering is faster; both because less
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  5397
     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
  5398
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5399
    |monoBits|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5400
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5401
    monoBits := self stevensonArceDitheredMonochromeBits.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5402
    ^ (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
  5403
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5404
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5405
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5406
5161
d6538957b675 changed #asStevensonArceDitheredMonochromeImage
sr
parents: 5160
diff changeset
  5407
     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
  5408
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5409
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5410
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5411
     i asStevensonArceDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5412
     i asOrderedDitheredMonochromeImage inspect.
5161
d6538957b675 changed #asStevensonArceDitheredMonochromeImage
sr
parents: 5160
diff changeset
  5413
     (i asThresholdMonochromeImage:0.5) inspect
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5414
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5415
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5416
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5417
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5418
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5419
     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
  5420
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5421
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5422
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5423
     i asStevensonArceDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5424
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5425
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5426
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5427
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5428
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5429
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5430
     i := Depth4Image
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5431
	     width:4
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5432
	     height:4
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5433
	     fromArray:#[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5434
			    16r01 16r23
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5435
			    16r45 16r67
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5436
			    16r89 16rab
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5437
			    16rcd 16ref
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5438
			].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5439
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5440
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5441
     i asStevensonArceDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5442
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5443
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5444
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5445
    "Created: 10.6.1996 / 12:38:29 / cg"
837
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  5446
    "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
  5447
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5448
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5449
asThresholdGrayFormOn:aDevice
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5450
    "return a thresholded grey form from the receiver image."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5451
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5452
    |depth|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5453
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5454
    (depth := aDevice depth) == 1 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5455
	^ self asThresholdMonochromeFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5456
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5457
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5458
    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5459
	makeDeviceGrayPixmapOn:aDevice
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5460
	depth:depth
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5461
	fromArray:(self
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5462
			orderedDitheredGrayBitsWithDitherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5463
			ditherWidth:4
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5464
			depth:depth)
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5465
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5466
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5467
     |i|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5468
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5469
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5470
     (i asThresholdGrayFormOn:Display) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5471
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5472
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5473
    "Created: 10.6.1996 / 18:38:31 / cg"
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  5474
    "Modified: 24.6.1997 / 22:19:46 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5475
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5476
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5477
asThresholdGrayImageDepth:depth
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5478
    "return a thresholded depth-x grey image from the receiver image."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5479
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  5480
    (depth == 1) ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5481
	"/ for monochrome, there is highly specialized
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5482
	"/ monochrome dither code available
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5483
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5484
	^ Depth1Image
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5485
	    width:width
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5486
	    height:height
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5487
	    fromArray:(
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5488
		self
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5489
		    orderedDitheredMonochromeBitsWithDitherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5490
		    ditherWidth:4)
800
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  5491
    ].
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  5492
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5493
    ^ (self class implementorForDepth:depth)
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5494
	width:width
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5495
	height:height
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5496
	fromArray:(
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5497
	    self
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5498
		orderedDitheredGrayBitsWithDitherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5499
		ditherWidth:4
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5500
		depth:depth)
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5501
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5502
    "
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5503
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5504
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5505
     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
  5506
     (i asThresholdGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5507
     (i asThresholdGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5508
     (i asThresholdGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5509
     (i asThresholdGrayImageDepth:8) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5510
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5511
     (i asOrderedDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5512
     (i asOrderedDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5513
     (i asOrderedDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5514
     (i asOrderedDitheredGrayImageDepth:8) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5515
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5516
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5517
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5518
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5519
     (i asFloydSteinbergDitheredGrayImageDepth:8) inspect.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5520
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5521
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5522
    "Created: 7.6.1996 / 18:13:33 / cg"
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  5523
    "Modified: 24.6.1997 / 22:19:52 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5524
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5525
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5526
asThresholdMonochromeFormOn:aDevice
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5527
    "return a threshold monochrome form from the image."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5528
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5529
    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5530
	asOrderedDitheredMonochromeFormOn:aDevice
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5531
	ditherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5532
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5533
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5534
    "
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5535
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5536
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5537
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5538
     i inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5539
     (i asThresholdMonochromeFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5540
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5541
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5542
     |i|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5543
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5544
     i := (Image fromFile:'goodies/bitmaps/a11.ico') magnifiedBy:10.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5545
     i inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5546
     (i asThresholdMonochromeFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5547
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5548
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5549
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5550
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5551
     i := Image fromFile:'goodies/bitmaps/granite.tiff'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5552
     i inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5553
     (i asThresholdMonochromeFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5554
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5555
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5556
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5557
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5558
     i := (Image fromFile:'goodies/bitmaps/PasteButton.tiff') magnifiedBy:10.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5559
     i inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5560
     (i asThresholdMonochromeFormOn:Display) inspect
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5561
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5562
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5563
    "Created: 7.6.1996 / 16:15:17 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5564
    "Modified: 10.6.1996 / 17:44:29 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5565
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5566
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5567
asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5568
    "return a threshold monochrome image from the image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5569
     Threshold means: brightness < 0.5 -> black / otherwise white"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5570
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5571
    ^ self
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5572
	asOrderedDitheredMonochromeImageWithDitherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5573
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5574
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5575
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5576
     |i i2|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5577
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5578
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5579
     i2 := i asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5580
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5581
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5582
     |i i2|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5583
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5584
     i := (Image fromFile:'/cdrom/icons/a/a11.ico') magnifiedBy:10.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5585
     i2 := i asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5586
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5587
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5588
     |i i2|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5589
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5590
     i := Image fromFile:'goodies/bitmaps/granite.tiff'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5591
     i2 := i asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5592
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5593
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5594
     |i i2|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5595
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5596
     i := (Image fromFile:'goodies/bitmaps/PasteButton.tiff') magnifiedBy:10.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5597
     i2 := i asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5598
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5599
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5600
    "Created: 7.6.1996 / 16:15:17 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5601
    "Modified: 7.6.1996 / 17:16:10 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5602
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5603
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5604
asThresholdMonochromeImage:thresholdBrighness
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5605
    "return a threshold monochrome image from the image.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5606
     The argument (0..1) gives the threshold value;
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5607
     Threshold means: brightness < threshold -> black / otherwise white"
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5608
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5609
    |value ditherMatrix|
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5610
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5611
    value := thresholdBrighness * 255.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5612
    ditherMatrix := ByteArray new:256 withAll:(value truncated).
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5613
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5614
    ^ self
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5615
	asOrderedDitheredMonochromeImageWithDitherMatrix:ditherMatrix
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5616
	ditherWidth:16
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5617
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5618
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5619
     |i|
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5620
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5621
     i := Image width:4 height:4 depth:4
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5622
		fromArray:#[ 16r01 16r23
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5623
			     16r45 16r67
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5624
			     16r89 16rab
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5625
			     16rcd 16ref ].
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5626
     i := i magnifiedBy:30.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5627
     i inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5628
     (i asThresholdMonochromeImage:0.125) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5629
     (i asThresholdMonochromeImage:0.25) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5630
     (i asThresholdMonochromeImage:0.5) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5631
     (i asThresholdMonochromeImage:0.75) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5632
     (i asThresholdMonochromeImage:1) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5633
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5634
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5635
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5636
     |i|
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5637
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5638
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5639
     i inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5640
     (i asThresholdMonochromeImage:0.125) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5641
     (i asThresholdMonochromeImage:0.25) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5642
     (i asThresholdMonochromeImage:0.5) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5643
     (i asThresholdMonochromeImage:0.625) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5644
     (i asThresholdMonochromeImage:0.75) inspect.
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
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5647
    "Created: 7.6.1996 / 16:15:17 / cg"
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5648
    "Modified: 8.6.1996 / 14:51:57 / cg"
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5649
!
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5650
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5651
clearMaskedPixels
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5652
    "assuming that I already have a device representation
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5653
     in deviceForm, clear any masked pixels.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5654
     This will allow faster drawing in the future."
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5655
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5656
    maskedPixelsAre0 == true ifTrue:[^ self].   "/ already cleared
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5657
    mask isNil ifTrue:[^ self].         "/ no mask
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5658
    deviceForm isNil ifTrue:[^ self].   "/ no device rep.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5659
    mask depth ~~ 1 ifTrue:[^ self].    "/ not done with alpha masks
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5660
6496
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  5661
    deviceForm 
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  5662
        foreground:Color allColor background:Color noColor function:#and;
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  5663
        copyPlaneFrom:(mask asFormOn:device) x:0 y:0 toX:0 y:0 width:width height:height.
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  5664
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  5665
"/    deviceForm clearMaskedPixels:(mask asFormOn:device).
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5666
    maskedPixelsAre0 := true.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5667
6496
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  5668
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5669
    "Created: 12.4.1997 / 12:18:05 / cg"
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5670
    "Modified: 12.4.1997 / 12:20:19 / cg"
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5671
!
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5672
3104
edc88b280153 added #exactOn: - for Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3092
diff changeset
  5673
exactOn:aDevice
3107
ed51e2c00f1d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3105
diff changeset
  5674
    "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
  5675
edc88b280153 added #exactOn: - for Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3092
diff changeset
  5676
    ^ self onDevice:aDevice
edc88b280153 added #exactOn: - for Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3092
diff changeset
  5677
!
edc88b280153 added #exactOn: - for Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3092
diff changeset
  5678
3105
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5679
exactOrNearestOn:aDevice
3107
ed51e2c00f1d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3105
diff changeset
  5680
    "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
  5681
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5682
    ^ self onDevice:aDevice
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5683
!
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5684
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5685
fromForm:aForm
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  5686
    "setup the receiver from a form"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5687
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5688
    |map c0 c1|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5689
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5690
    width := aForm width.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5691
    height := aForm height.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5692
    bitsPerSample := self bitsPerSample.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5693
    samplesPerPixel := self samplesPerPixel.
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5694
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5695
    aForm hasBits ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5696
	"/ must read the data from the device
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5697
	self from:aForm in:(0@0 extent:aForm extent).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5698
	^ self
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5699
    ].
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5700
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5701
    "/ the form has all data available
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5702
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  5703
    self bits:(aForm bits).
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5704
    map := aForm colorMap.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5705
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5706
    aForm depth == 1 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5707
	map isNil ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5708
	    photometric := #whiteIs0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5709
	] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5710
	    c0 := map at:1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5711
	    c1 := map at:2.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5712
	    ((c0 = Color white)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5713
	    and:[c1 = Color black]) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5714
		photometric := #whiteIs0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5715
	    ] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5716
		((c0 = Color black)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5717
		and:[c1 = Color white]) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5718
		    photometric := #blackIs0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5719
		] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5720
		    photometric := #palette.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5721
		    self setColorMap:(Array with:c0 with:c1).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5722
		]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5723
	    ]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5724
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5725
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5726
	map notNil ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5727
	    photometric := #palette.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5728
	    self setColorMap:(map copy).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5729
	] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5730
	    "
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5731
	     photometric stays at default
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5732
	     (which is rgb for d24, greyscale for others)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5733
	    "
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5734
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5735
    ].
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  5736
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5737
    "Modified: 5.7.1996 / 16:24:31 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5738
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5739
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5740
fromImage:anImage
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5741
    "setup the receiver from another image.
4888
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5742
     Color precision may be lost, if conversion is from a higher depth image.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5743
     WARNING:
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5744
     This implementation is a slow fallback (the loop over the
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5745
     source pixels is very slow). If this method is used heavily, you
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5746
     may want to redefine it in concrete subclasses for common source images."
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5747
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5748
    ^ 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
  5749
!
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5750
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5751
fromImage:anImage photometric:photometricOrNil
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5752
    "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
  5753
     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
  5754
     WARNING:
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5755
     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
  5756
     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
  5757
     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
  5758
3363
de7e8628d329 fixed conversion of 3-3-2 8-bit truecolor images
Claus Gittinger <cg@exept.de>
parents: 3273
diff changeset
  5759
    |map clr mappedRowPixels samePhotometric
1784
25b96d8904c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1783
diff changeset
  5760
     h "{ Class: SmallInteger }"
5712
b4d960599bc8 changed: #fromImage:photometric:
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  5761
     w "{ Class: SmallInteger }"
b4d960599bc8 changed: #fromImage:photometric:
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  5762
     a r g b rgbPixel|
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5763
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5764
    width := anImage width.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5765
    height := anImage height.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5766
    bitsPerSample := self bitsPerSample.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5767
    samplesPerPixel := self samplesPerPixel.
4859
553f9013f270 only try to fetch colormap for palette images
Claus Gittinger <cg@exept.de>
parents: 4858
diff changeset
  5768
4888
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5769
    photometricOrNil isNil ifTrue:[
6379
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5770
        photometric := self class defaultPhotometric
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5771
        "/ photometric := anImage photometric
4888
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5772
    ] ifFalse:[
7156
97b4f12aa796 #BUGFIX
matilk
parents: 7126
diff changeset
  5773
        photometricOrNil == #rgba ifTrue:[
97b4f12aa796 #BUGFIX
matilk
parents: 7126
diff changeset
  5774
            samplesPerPixel == 3 ifTrue:[ photometric := #rgb ]
97b4f12aa796 #BUGFIX
matilk
parents: 7126
diff changeset
  5775
        ] ifFalse:[
97b4f12aa796 #BUGFIX
matilk
parents: 7126
diff changeset
  5776
            photometric := photometricOrNil
97b4f12aa796 #BUGFIX
matilk
parents: 7126
diff changeset
  5777
        ].
4888
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5778
    ].
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5779
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5780
    photometric == #palette ifTrue:[
6379
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5781
        self colormapFromImage:anImage photometric:photometric.
4859
553f9013f270 only try to fetch colormap for palette images
Claus Gittinger <cg@exept.de>
parents: 4858
diff changeset
  5782
    ].
1374
ab515c0576c6 preserve mask when creating an image from another image.
Claus Gittinger <cg@exept.de>
parents: 1362
diff changeset
  5783
    self mask:anImage mask.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5784
3363
de7e8628d329 fixed conversion of 3-3-2 8-bit truecolor images
Claus Gittinger <cg@exept.de>
parents: 3273
diff changeset
  5785
    samePhotometric := (photometric == anImage photometric).
de7e8628d329 fixed conversion of 3-3-2 8-bit truecolor images
Claus Gittinger <cg@exept.de>
parents: 3273
diff changeset
  5786
de7e8628d329 fixed conversion of 3-3-2 8-bit truecolor images
Claus Gittinger <cg@exept.de>
parents: 3273
diff changeset
  5787
    ((self depth = anImage depth)
de7e8628d329 fixed conversion of 3-3-2 8-bit truecolor images
Claus Gittinger <cg@exept.de>
parents: 3273
diff changeset
  5788
    and:[samePhotometric]) ifTrue:[
6379
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5789
        self bits:(anImage bits copy).
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5790
        ^ self.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  5791
    ].
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  5792
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  5793
    self bits:(ByteArray uninitializedNew:(self bytesPerRow * height)).
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5794
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5795
    self depth >= anImage depth ifTrue:[
6379
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5796
        anImage depth <= 12 ifTrue:[
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5797
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5798
            "/ if my depth is greater, all colors can be represented,
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5799
            "/ and the loop can be done over pixel values ...
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5800
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5801
            (colorMap isNil or:[samePhotometric not]) ifTrue:[
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5802
                map := Array new:(1 bitShift:anImage depth).
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5803
                1 to:map size do:[:i |
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5804
                    clr := anImage colorFromValue:(i - 1).
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5805
                    map at:i put:(self valueFromColor:clr).
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5806
                ].
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5807
            ].
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5808
            mappedRowPixels := self pixelArraySpecies new:width.
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5809
            h := height-1.
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5810
            w := width.
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5811
            0 to:h do:[:row |
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5812
                anImage rowAt:row into:mappedRowPixels startingAt:1.
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5813
                map notNil ifTrue:[
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5814
                    1 to:w do:[:i |
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5815
                        mappedRowPixels at:i put:(map at:(mappedRowPixels at:i)+1)
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5816
                    ].
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5817
                ].
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5818
                self rowAt:row putAll:mappedRowPixels
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5819
            ].
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5820
            ^ self
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5821
        ].
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5822
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5823
5712
b4d960599bc8 changed: #fromImage:photometric:
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  5824
    "/ a hack, for now - alpha is in the low-byte !!!!!!
b4d960599bc8 changed: #fromImage:photometric:
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  5825
    (self depth == 24 and:[anImage depth == 32]) ifTrue:[
6379
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5826
        (samePhotometric and:[photometric == #rgb]) ifTrue:[
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5827
            "/ can do the bits by simple stripping off the alpha channel
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5828
            anImage valuesFromX:0 y:0 toX:(width-1) y:(height-1) do:[:x :y :pixel |
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5829
                "/ bgra-pixel
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5830
                a := pixel bitAnd:16rFF.
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5831
                r := (pixel bitShift:-8) bitAnd:16rFF.
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5832
                g := (pixel bitShift:-16) bitAnd:16rFF.
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5833
                b := (pixel bitShift:-24) bitAnd:16rFF.
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5834
                rgbPixel := r + (g bitShift:8) + (b bitShift:16).
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5835
                self pixelAtX:x y:y put:rgbPixel
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5836
            ].
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5837
            ^ self
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5838
        ].
5712
b4d960599bc8 changed: #fromImage:photometric:
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  5839
    ].
b4d960599bc8 changed: #fromImage:photometric:
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  5840
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5841
    anImage colorsFromX:0 y:0 toX:(width-1) y:(height-1) do:[:x :y :clr |
6379
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5842
        self colorAtX:x y:y put:clr
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5843
    ].
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5844
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5845
    "
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5846
     |i i2 i4 i8 i16 i24|
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5847
6496
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  5848
     i := GenericToolbarIconLibrary desktop32x32Icon2.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5849
     i inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5850
     i2 := Depth2Image fromImage:i.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5851
     i2 inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5852
     i4 := Depth4Image fromImage:i.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5853
     i4 inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5854
     i8 := Depth8Image fromImage:i.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5855
     i8 inspect.
6496
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  5856
     i16 := Depth16Image fromImage:i.
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  5857
     i16 inspect.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5858
     i24 := Depth24Image fromImage:i.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5859
     i24 inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5860
    "
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5861
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5862
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5863
     |i i24|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5864
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5865
     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
  5866
     Transcript showCR:(
6379
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5867
        Time millisecondsToRun:[
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5868
            i24 := Depth24Image fromImage:i.
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5869
        ]
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5870
     ).
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5871
     i24 inspect.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5872
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5873
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5874
     |i i24|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5875
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5876
     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
  5877
     MessageTally spyOn:[
6379
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5878
        i24 := Depth24Image fromImage:i.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5879
     ]
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5880
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5881
5712
b4d960599bc8 changed: #fromImage:photometric:
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  5882
    "Modified: / 05-02-2011 / 17:46:58 / cg"
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5883
!
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5884
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5885
fromSubImage:anImage in:aRectangle
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5886
    "setup the receiver from another image, extracting a rectangular area. 
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5887
     As with layouts, the rectangle may contain integers (= nr of pixels) or float numbers (= relative size).
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5888
     Color precision may be lost, if conversion is from a higher depth image. 
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5889
     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
  5890
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5891
    |w h xL yT imgWidth imgHeight|
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5892
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5893
    w := aRectangle width.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5894
    h := aRectangle height.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5895
    xL := aRectangle left.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5896
    yT := aRectangle top.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5897
    imgWidth := anImage width.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5898
    imgHeight := anImage height.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5899
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5900
    xL isFloat ifTrue:[ 
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5901
        xL := (imgWidth * xL) rounded min: imgWidth.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5902
    ].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5903
    yT isFloat ifTrue:[ 
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5904
        yT := (imgHeight * yT) rounded min:imgHeight.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5905
    ].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5906
    w isFloat ifTrue:[ 
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5907
        w := (imgWidth * w) rounded.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5908
    ].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5909
    w := w min:(imgWidth - xL).
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5910
    h isFloat ifTrue:[ 
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5911
        h := (imgHeight * h) rounded.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5912
    ].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5913
    h := h min:(imgHeight - yT).
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5914
    self fromSubImage:anImage inX:xL y:yT width:w height:h
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5915
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5916
    "
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5917
     |i i2 i4 i8 i16 i24|
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5918
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5919
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5920
     i inspect.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5921
     i4 := Depth4Image fromSubImage:i in:(300@160 corner:340@200).
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5922
     i4 inspect.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5923
     i8 := Depth8Image fromSubImage:i in:(300@160 corner:340@200).
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5924
     i8 inspect.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5925
     i24 := Depth24Image fromSubImage:i in:(300@160 corner:340@200).
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5926
     i24 inspect.
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
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5929
    "Created: / 20.9.1995 / 01:06:02 / claus"
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5930
    "Modified: / 20.9.1995 / 10:15:37 / claus"
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5931
    "Modified: / 18.5.1999 / 20:06:55 / cg"
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5932
!
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5933
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5934
fromSubImage:anImage inX:xL y:yT width:w height:h
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5935
    "setup the receiver from another image, extracting a rectangular area. 
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5936
     Color precision may be lost, if conversion is from a higher depth image. 
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5937
     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
  5938
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5939
     WARNING:
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5940
       This implementation is a slow fallback (the loop over the
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5941
       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
  5942
       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
  5943
       of creating a subImage with the same depth & palette."
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5944
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5945
    |xR yB imagesMask maskClass|
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5946
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5947
    width := w.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5948
    height := h.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5949
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
  5950
    self createPixelStore.
3458
b2e098e6288b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3457
diff changeset
  5951
    depth := self depth.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5952
    bitsPerSample := self bitsPerSample.
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
  5953
    "/ bitsPerPixel := self bitsPerPixel.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5954
    samplesPerPixel := self samplesPerPixel.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5955
    self colormapFromImage:anImage.
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5956
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5957
    xR := xL + w - 1.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5958
    yB := yT + h - 1.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5959
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5960
    ((photometric == anImage photometric)
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5961
    and:[self bitsPerPixel = anImage bitsPerPixel
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5962
    and:[colorMap = anImage colorMap]]) ifTrue:[
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5963
        "/ can do it by value
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5964
        anImage
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5965
            valuesFromX:xL y:yT toX:xR y:yB
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5966
            do:[:x :y :pixelValue | self pixelAtX:x-xL y:y-yT put:pixelValue ]
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5967
    ] ifFalse:[
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5968
        "/ must do it by colors
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5969
        anImage
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5970
            colorsFromX:xL y:yT toX:xR y:yB
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5971
            do:[:x :y :clr | self colorAtX:x-xL y:y-yT put:clr ]
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5972
    ].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5973
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5974
    (imagesMask := anImage mask) notNil ifTrue:[
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5975
        imagesMask depth == 1 ifTrue:[
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5976
            maskClass := ImageMask
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5977
        ] ifFalse:[
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5978
            maskClass := imagesMask class.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5979
        ].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5980
        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
  5981
    ].
1963
ab2d96e4e140 care for masks in copy/copySubImage;
tz
parents: 1962
diff changeset
  5982
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5983
    "
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5984
     |i i2 i4 i8 i16 i24|
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5985
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5986
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5987
     i inspect.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5988
     i4 := Depth4Image fromSubImage:i in:(300@160 corner:340@200).
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5989
     i4 inspect.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5990
     i8 := Depth8Image fromSubImage:i in:(300@160 corner:340@200).
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5991
     i8 inspect.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5992
     i24 := Depth24Image fromSubImage:i in:(300@160 corner:340@200).
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5993
     i24 inspect.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5994
    "
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5995
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5996
    "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
  5997
    "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
  5998
    "Modified: / 18.5.1999 / 20:06:55 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5999
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  6000
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6001
monochromeOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6002
    "return a monochrome device image of the receiver for aDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6003
     (monochrome, even if device supports colors)"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6004
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6005
    ((aDevice == device) and:[monoDeviceForm notNil]) ifTrue:[^ self].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6006
    (device notNil and:[aDevice ~~ device]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6007
	"oops, I am already accociated to another device
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6008
	 - need a copy ...
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6009
	"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6010
	^ self copy monochromeOn:aDevice
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6011
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6012
    monoDeviceForm := self asMonochromeFormOn:aDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6013
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6014
3105
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  6015
nearestOn:aDevice
3107
ed51e2c00f1d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3105
diff changeset
  6016
    "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
  6017
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  6018
    ^ self onDevice:aDevice
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  6019
!
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  6020
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6021
on:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6022
    "return an image with the same pixels as the receiver, but
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6023
     associated to aDevice. If the receiver is not yet bound to
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6024
     a device, this will be the receiver. Otherwise, a new image
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6025
     is returned."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6026
3623
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  6027
    "/ send out a warning: #on: is typically used to create views
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  6028
    "/ operating on a model.
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  6029
    "/ Please use #onDevice: to avoid confusion.
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  6030
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  6031
    <resource:#obsolete>
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  6032
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  6033
    self obsoleteMethodWarning:'use #onDevice:'.
3477
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6034
    ^ self onDevice:aDevice
1496
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  6035
!
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  6036
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  6037
onDevice:aDevice
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  6038
    "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
  6039
     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
  6040
     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
  6041
     is returned."
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  6042
2980
409e9547a45c ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  6043
    aDevice isNil ifTrue:[^ self].
3477
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6044
    ((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ self].
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6045
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6046
    (device notNil and:[aDevice ~~ device]) ifTrue:[
6493
7785d3d8458b class: Image
Stefan Vogel <sv@exept.de>
parents: 6390
diff changeset
  6047
        "oops, I am already associated to another device
7785d3d8458b class: Image
Stefan Vogel <sv@exept.de>
parents: 6390
diff changeset
  6048
         - need a copy ...
7785d3d8458b class: Image
Stefan Vogel <sv@exept.de>
parents: 6390
diff changeset
  6049
        "
7785d3d8458b class: Image
Stefan Vogel <sv@exept.de>
parents: 6390
diff changeset
  6050
        ^ self copy onDevice:aDevice
3477
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6051
    ].
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6052
    deviceForm := self asFormOn:aDevice.
6496
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  6053
    device := aDevice.
3477
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6054
    maskedPixelsAre0 := nil.
6496
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  6055
    mask notNil ifTrue:[
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  6056
        self clearMaskedPixels.
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  6057
    ].
3477
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6058
    Lobby register:self
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6059
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6060
    "Modified: / 22.8.1998 / 13:34:24 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6061
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6062
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6063
!Image methodsFor:'converting greyscale images'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6064
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6065
greyImageAsFormOn:aDevice
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6066
    "return a grey-deviceForm from the grey image."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6067
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  6068
    |pictureDepth nPlanes|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6069
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  6070
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6071
    nPlanes := samplesPerPixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6072
    (nPlanes == 2) ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6073
	'Image [info]: alpha plane ignored' infoPrintCR.
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  6074
    ].
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  6075
    "/ first plane only
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6076
    pictureDepth := bitsPerSample at:1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6077
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6078
    "monochrome is very easy ..."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6079
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6080
    (pictureDepth == 1) ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6081
	^ Form width:width height:height fromArray:self bits onDevice:aDevice
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6082
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6083
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6084
    (aDevice visualType == #TrueColor) ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6085
	^ self greyImageAsTrueColorFormOn:aDevice
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6086
    ].
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6087
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6088
    "/ PseudoColor conversion also works for StaticColor,
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6089
    "/ GrayScale and DirectColor; although possibly with suboptimal results
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6090
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6091
    ^ self greyImageAsPseudoFormOn:aDevice
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6092
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6093
    "Modified: 19.10.1997 / 05:17:25 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6094
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6095
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6096
greyImageAsPseudoFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6097
    "return an 8-bit pseudo Form from the grey image"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6098
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6099
    |wideBits pictureDepth f map
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6100
     colorMap usedColors nUsed aColor
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6101
     nColors "{ Class: SmallInteger }"
1766
08b918d293a6 fixed conversion of greyScale images with colorCube
Claus Gittinger <cg@exept.de>
parents: 1764
diff changeset
  6102
     range id
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6103
     cube nR nG nB grayColors
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6104
     fit|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6105
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6106
    pictureDepth := bitsPerSample at:1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6107
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6108
    (#(2 4 8) includes:pictureDepth) ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6109
	self error:'currently only depth-2, 4 or 8 supported'.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6110
	^ nil
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6111
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6112
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6113
    wideBits := ByteArray uninitializedNew:(width * height).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6114
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6115
    (pictureDepth == 8) ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6116
	"for 8bits, we scan for used colors first;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6117
	 to avoid allocating too many colors"
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6118
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6119
	(grayColors := aDevice fixGrayColors) notNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6120
	    DitherAlgorithm == #floydSteinberg ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6121
		f := self
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6122
		       asFloydSteinbergDitheredDepth8FormOn:aDevice
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6123
		       colors:grayColors
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6124
	    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6125
	    f notNil ifTrue:[^ f].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6126
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6127
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6128
	(cube := aDevice fixColors) notNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6129
	    nR := aDevice numFixRed.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6130
	    nG := aDevice numFixGreen.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6131
	    nB := aDevice numFixBlue.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6132
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6133
	    DitherAlgorithm == #floydSteinberg ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6134
		f := self
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6135
		       asFloydSteinbergDitheredDepth8FormOn:aDevice
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6136
		       colors:cube
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6137
		       nRed:nR
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6138
		       nGreen:nG
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6139
		       nBlue:nB.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6140
	    ] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6141
		f := self
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6142
		       asNearestPaintDepth8FormOn:aDevice
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6143
		       colors:cube
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6144
		       nRed:nR
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6145
		       nGreen:nG
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6146
		       nBlue:nB.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6147
	    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6148
	    f notNil ifTrue:[^ f].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6149
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6150
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6151
	usedColors := self bits usedValues.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6152
	nUsed := usedColors max + 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6153
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6154
	colorMap := Array new:nUsed.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6155
	range := 100 / 255.0.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6156
	usedColors do:[:grey |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6157
	    colorMap at:(grey + 1) put:(Color gray:(range * grey))
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6158
	].
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  6159
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6160
	nColors := (1 bitShift:pictureDepth).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6161
	colorMap := Array new:nColors.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6162
	range := 100 / (nColors - 1) asFloat.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6163
	1 to:nColors do:[:i |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6164
	    colorMap at:i put:(Color gray:(i - 1) * range).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6165
	].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6166
    ].
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6167
    photometric ~~ #blackIs0 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6168
	colorMap reverse
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6169
    ].
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6170
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6171
    "allocate those colors & setup the translation map"
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6172
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6173
    fit := true.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6174
    map := ByteArray uninitializedNew:256.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6175
    nColors := colorMap size.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6176
    1 to:nColors do:[:i |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6177
	aColor := colorMap at:i.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6178
	aColor notNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6179
	    aColor := aColor onDevice:aDevice.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6180
	    colorMap at:i put:aColor.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6181
	    id := aColor colorId.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6182
	    id isNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6183
		id := 0.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6184
		fit := false.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6185
	    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6186
	    map at:i put:id
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6187
	]
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  6188
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6189
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6190
    fit ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6191
	"/ here comes the hard part - some grey value
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6192
	"/ could not be allocated.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6193
	"/ Must dither.
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6194
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6195
    ].
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6196
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6197
    "expand & translate"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6198
    self bits
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6199
	expandPixels:pictureDepth
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6200
	width:width height:height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6201
	into:wideBits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6202
	mapping:map.
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  6203
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  6204
    f := Form width:width height:height depth:8 onDevice:aDevice.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6205
    f isNil ifTrue:[^ nil].
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6206
    f colorMap:colorMap.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6207
    f initGC.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6208
    aDevice
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6209
	drawBits:wideBits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6210
	depth:8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6211
	padding:8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6212
	width:width height:height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6213
	x:0 y:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6214
	into:(f id)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6215
	x:0 y:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6216
	width:width height:height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6217
	with:(f gcId).
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6218
    ^ f
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  6219
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6220
    "Modified: 19.10.1997 / 05:19:44 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6221
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  6222
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6223
greyImageAsTrueColorFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6224
    "return a true-color device-form for the grey-image receiver.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6225
     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
  6226
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6227
    |depth
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  6228
     myDepth    "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  6229
     nColors    "{ Class: SmallInteger }"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6230
     colorValues
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6231
     scaleDown
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  6232
     scaleRed   "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  6233
     scaleGreen "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  6234
     scaleBlue  "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  6235
     redShift   "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  6236
     blueShift  "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  6237
     greenShift "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6238
     form bestFormat usedDeviceDepth usedDeviceBitsPerPixel imageBits
1175
5595569cfbd3 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 1170
diff changeset
  6239
     greyValue  "{ Class: SmallInteger }"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6240
     h          "{ Class: SmallInteger }"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6241
     w          "{ Class: SmallInteger }"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6242
     pixelArray newPixelArray i|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6243
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6244
    "/ this is a slow fallback method; this ought to be
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6245
    "/ redefined in DepthxImage for more performance.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6246
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6247
    depth := aDevice depth.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6248
    myDepth := self depth.
5315
cbac968cee6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5314
diff changeset
  6249
    myDepth > 16 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6250
	self error:'unsupported depth' mayProceed:true.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6251
	^ nil
5315
cbac968cee6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5314
diff changeset
  6252
    ].
5314
517094dfa71c changed #greyImageAsTrueColorFormOn:
Claus Gittinger <cg@exept.de>
parents: 5313
diff changeset
  6253
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6254
    "/ compute scale to map from my pixels into devices range
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6255
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6256
    scaleDown := 1 bitShift:myDepth.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6257
    scaleRed := (1 bitShift:aDevice bitsRed).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6258
    scaleGreen := (1 bitShift:aDevice bitsGreen).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6259
    scaleBlue := (1 bitShift:aDevice bitsBlue).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6260
    redShift := aDevice shiftRed.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6261
    greenShift := aDevice shiftGreen.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6262
    blueShift := aDevice shiftBlue.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6263
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  6264
    "/ prepare the map
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  6265
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6266
    nColors := (1 bitShift:myDepth).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6267
    colorValues := Array new:nColors.
6256
1e510d7aea8e Inline block variable rename to avoid stc bug
Stefan Vogel <sv@exept.de>
parents: 6166
diff changeset
  6268
    1 to:nColors do:[:colorIdx |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6269
	|v gv bv rv nv|
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6270
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6271
	"/ scale down to 0..1
6256
1e510d7aea8e Inline block variable rename to avoid stc bug
Stefan Vogel <sv@exept.de>
parents: 6166
diff changeset
  6272
	v := (colorIdx-1) / scaleDown.
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6273
	rv := (v * scaleRed) truncated.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6274
	gv := (v * scaleGreen) truncated.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6275
	bv := (v * scaleBlue) truncated.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6276
	nv := rv bitShift:redShift.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6277
	nv := nv bitOr:(gv bitShift:greenShift).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6278
	nv := nv bitOr:(bv bitShift:blueShift).
6256
1e510d7aea8e Inline block variable rename to avoid stc bug
Stefan Vogel <sv@exept.de>
parents: 6166
diff changeset
  6279
	colorValues at:colorIdx put:nv
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6280
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6281
    photometric == #whiteIs0 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6282
	"/ reverse the order; 0 is brightest
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6283
	colorValues reverse
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6284
    ].
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6285
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6286
    bestFormat := self bestSupportedImageFormatFor:aDevice.
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  6287
    usedDeviceDepth := bestFormat at:#depth.
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  6288
    usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6289
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6290
    "/ the temporary helper image is only needed to allow
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6291
    "/ the rowAt:putAll: calls below.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6292
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  6293
    i := (Image implementorForDepth:usedDeviceBitsPerPixel) new.
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  6294
    i width:width height:height.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
  6295
    i createPixelStore.
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
  6296
    imageBits := i bits.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6297
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6298
    "/ now, walk over the image and replace
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6299
    "/ colorMap indices by color values in the bits array
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6300
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6301
    h := height - 1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6302
    w := width - 1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6303
    pixelArray := self pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6304
    newPixelArray := i pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6305
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6306
    0 to:h do:[:y |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6307
	self rowAt:y into:pixelArray.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6308
	0 to:w do:[:x |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6309
	    greyValue := pixelArray at:(x+1).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6310
	    newPixelArray at:(x+1) put:(colorValues at:greyValue + 1).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6311
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6312
	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
  6313
    ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  6314
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  6315
    form := Form width:width height:height depth:usedDeviceDepth onDevice:aDevice.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6316
    form isNil ifTrue:[^ nil].
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6317
    form initGC.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6318
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6319
    form
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6320
	copyBitsFrom:imageBits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6321
	bitsPerPixel:usedDeviceBitsPerPixel
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6322
	depth:usedDeviceDepth
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6323
	padding:8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6324
	width:width height:height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6325
	x:0 y:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6326
	toX:0 y:0.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6327
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6328
    ^ form
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6329
5710
9928e8b52195 changed: #greyImageAsTrueColorFormOn:
Claus Gittinger <cg@exept.de>
parents: 5655
diff changeset
  6330
    "Created: / 20-10-1995 / 22:05:10 / cg"
9928e8b52195 changed: #greyImageAsTrueColorFormOn:
Claus Gittinger <cg@exept.de>
parents: 5655
diff changeset
  6331
    "Modified: / 05-02-2011 / 10:40:13 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6332
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
  6333
48194c26a46c Initial revision
claus
parents:
diff changeset
  6334
!Image methodsFor:'converting palette images'!
48194c26a46c Initial revision
claus
parents:
diff changeset
  6335
48194c26a46c Initial revision
claus
parents:
diff changeset
  6336
paletteImageAsFormOn:aDevice
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  6337
    "return a device-form for the palette-image receiver"
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  6338
380
c5ffc6d48a9e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 379
diff changeset
  6339
    |type ddepth|
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6340
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  6341
    ddepth := aDevice depth.
379
d74cdaa0adcb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
  6342
3940
b1b7dc76d7d7 not ifTrue -> ifFalse
Claus Gittinger <cg@exept.de>
parents: 3939
diff changeset
  6343
    aDevice hasGrayscales ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6344
	^ self asMonochromeFormOn:aDevice
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  6345
    ].
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  6346
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6347
    ((type := aDevice visualType) == #StaticGray) ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6348
	ddepth == 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6349
	    ^ self paletteImageAsGray8FormOn:aDevice
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6350
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6351
	^ self asGrayFormOn:aDevice
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6352
    ].
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  6353
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6354
    (type == #TrueColor) ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6355
	DitherAlgorithm == #floydSteinberg ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6356
	    ddepth == 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6357
		self depth == 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6358
		    "/ use fixColor dither algorithm
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6359
		    ^ self asDitheredTrueColor8FormOn:aDevice
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6360
		]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6361
	    ]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6362
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6363
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6364
	^ self paletteImageAsTrueColorFormOn:aDevice
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6365
    ].
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6366
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6367
    "/ the PseudoColor conversion also works for
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6368
    "/ StaticColor, GrayScale & DirectColor; although possibly with suboptimal results
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6369
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6370
    ^ self paletteImageAsPseudoFormOn:aDevice
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6371
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6372
    "Modified: 14.6.1996 / 19:31:01 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6373
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  6374
48194c26a46c Initial revision
claus
parents:
diff changeset
  6375
paletteImageAsPseudoFormOn:aDevice
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  6376
    "return a pseudo-deviceForm from the palette image."
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6377
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  6378
    |tempImage d temp8|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  6379
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  6380
    d := self depth.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6381
    (#(1 2 4 8) includes:d) ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6382
	"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6383
	 fallback code for some depth's:
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6384
	 create a temporary Depth8Image and use its conversion method
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6385
	"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6386
	temp8 := ByteArray uninitializedNew:(width * height).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6387
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6388
	self bits
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6389
	    expandPixels:d
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6390
	    width:width height:height
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6391
	    into:temp8
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6392
	    mapping:nil.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6393
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6394
	tempImage := Image width:width height:height depth:8 fromArray:temp8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6395
	tempImage colorMap:colorMap.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6396
	^ tempImage paletteImageAsPseudoFormOn:aDevice
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  6397
    ].
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  6398
    ^ self subclassResponsibility
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6399
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  6400
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6401
paletteImageAsTrueColorFormOn:aDevice
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6402
    "return a true-color device-form for the palette-image receiver."
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6403
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6404
    |depth
209
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  6405
     nColors "{ Class: SmallInteger }"
1605
64151392ff64 added generic #paletteImageAsTrueColorForm implementation
Claus Gittinger <cg@exept.de>
parents: 1595
diff changeset
  6406
     h       "{ Class: SmallInteger }"
64151392ff64 added generic #paletteImageAsTrueColorForm implementation
Claus Gittinger <cg@exept.de>
parents: 1595
diff changeset
  6407
     pixel   "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6408
     colorValues
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6409
     scaleRed scaleGreen scaleBlue redShift greenShift blueShift
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6410
     form imageBits bestFormat usedDeviceDepth usedDeviceBitsPerPixel
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6411
     i pixelArray newPixelArray
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6412
     clr r g b rv gv bv v "{ Class: SmallInteger }" |
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6413
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6414
    "/ this is a slow fallback method; this ought to be
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6415
    "/ redefined in DepthxImage for more performance.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6416
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6417
    depth := aDevice depth.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6418
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6419
    bestFormat := self bestSupportedImageFormatFor:aDevice.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6420
    usedDeviceDepth := bestFormat at:#depth.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6421
    usedDeviceDepth == 1 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6422
	^ self asMonochromeFormOn:aDevice.
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6423
    ].
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6424
    usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6425
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6426
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6427
    scaleRed := ((1 bitShift:aDevice bitsRed) - 1) / 255.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6428
    scaleGreen := ((1 bitShift:aDevice bitsGreen) - 1) / 255.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6429
    scaleBlue := ((1 bitShift:aDevice bitsBlue) - 1) / 255.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6430
    redShift := aDevice shiftRed.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6431
    greenShift := aDevice shiftGreen.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6432
    blueShift := aDevice shiftBlue.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6433
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6434
    nColors := colorMap size.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6435
    nColors <= 4096 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6436
	"/ precompute scales to map from 0..100 into devices range
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6437
	"/ (this may be different for the individual components)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6438
	colorValues := Array uninitializedNew:nColors.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6439
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6440
	1 to:nColors do:[:index |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6441
	    r := colorMap redByteAt:index.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6442
	    g := colorMap greenByteAt:index.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6443
	    b := colorMap blueByteAt:index.
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6444
"/        clr := colorMap at:index.
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6445
	    true "clr notNil" ifTrue:[
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6446
"/            r := clr red.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6447
"/            g := clr green.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6448
"/            b := clr blue.
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6449
		rv := (r * scaleRed) rounded.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6450
		gv := (g * scaleGreen) rounded.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6451
		bv := (b * scaleBlue) rounded.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6452
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6453
		v := rv bitShift:redShift.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6454
		v := v bitOr:(gv bitShift:greenShift).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6455
		v := v bitOr:(bv bitShift:blueShift).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6456
		colorValues at:index put:v.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6457
"/ clr print. ' ' print.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6458
"/ rv print. ' ' print. gv print. ' ' print. bv print. ' ' print.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6459
"/ ' -> ' print. v printNL.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6460
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6461
	    ]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6462
	].
2864
dd151bfdff9d care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents: 2832
diff changeset
  6463
    ].
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6464
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6465
    "/ the temporary helper image is only needed to allow
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6466
    "/ the rowAt:putAll: calls below.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6467
1665
e0329f98904d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1664
diff changeset
  6468
    i := (Image implementorForDepth:usedDeviceBitsPerPixel) new.
e0329f98904d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1664
diff changeset
  6469
    i width:width height:height.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
  6470
    i createPixelStore.
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
  6471
    imageBits := i bits.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6472
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6473
    "/ now, walk over the image and replace
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6474
    "/ colorMap indices by color values in the bits array
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6475
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6476
    h := height - 1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6477
    pixelArray := self pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6478
    newPixelArray := i pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6479
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6480
    colorValues notNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6481
	0 to:h do:[:y |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6482
	    self rowAt:y into:pixelArray.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6483
	    1 to:width do:[:x |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6484
		pixel := pixelArray at:x.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6485
		newPixelArray at:x put:(colorValues at:pixel + 1 ifAbsent:0).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6486
	    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6487
	    i rowAt:y putAll:newPixelArray.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6488
	].
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6489
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6490
	0 to:h do:[:y |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6491
	    self rowAt:y into:pixelArray.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6492
	    1 to:width do:[:x |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6493
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6494
		pixel := pixelArray at:x.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6495
		clr := self colorFromValue:pixel.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6496
		r := clr redByte.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6497
		g := clr greenByte.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6498
		b := clr blueByte.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6499
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6500
		rv := (r * scaleRed) rounded.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6501
		gv := (g * scaleGreen) rounded.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6502
		bv := (b * scaleBlue) rounded.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6503
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6504
		v := rv bitShift:redShift.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6505
		v := v bitOr:(gv bitShift:greenShift).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6506
		v := v bitOr:(bv bitShift:blueShift).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6507
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6508
		newPixelArray at:x put:v.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6509
	    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6510
	    i rowAt:y putAll:newPixelArray.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6511
	].
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  6512
    ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  6513
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  6514
    form := Form width:width height:height depth:usedDeviceDepth onDevice:aDevice.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6515
    form isNil ifTrue:[^ nil].
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6516
    form initGC.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6517
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6518
    form
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6519
	copyBitsFrom:imageBits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6520
	bitsPerPixel:usedDeviceBitsPerPixel
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6521
	depth:usedDeviceDepth
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6522
	padding:8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6523
	width:width height:height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6524
	x:0 y:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6525
	toX:0 y:0.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6526
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6527
    ^ form
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6528
2185
756d58c52113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2182
diff changeset
  6529
    "Modified: / 24.7.1998 / 00:56:14 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6530
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
  6531
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6532
!Image methodsFor:'converting rgb images'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6533
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6534
asDitheredTrueColor8FormOn:aDevice
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6535
    "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
  6536
     Return the device-form.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  6537
     This method is only valid for trueColor displays."
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6538
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6539
    |fixColors pixel
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6540
     dstIdx     "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6541
     shiftRed   "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6542
     shiftGreen "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6543
     shiftBlue  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6544
     nRed    "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6545
     nGreen  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6546
     nBlue   "{ Class: SmallInteger }"|
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6547
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6548
    shiftRed := aDevice shiftRed.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6549
    shiftGreen := aDevice shiftGreen.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6550
    shiftBlue := aDevice shiftBlue.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6551
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6552
    nRed := (1 bitShift:aDevice bitsRed).
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6553
    nGreen := (1 bitShift:aDevice bitsGreen).
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6554
    nBlue := (1 bitShift:aDevice bitsBlue).
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6555
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6556
    fixColors := Array new:(nRed * nGreen * nBlue).
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6557
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6558
    dstIdx := 1.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6559
    0 to:nRed - 1 do:[:sR |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6560
	0 to:nGreen - 1 do:[:sG |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6561
	    0 to:nBlue - 1 do:[:sB |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6562
		pixel := (sR bitShift:shiftRed)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6563
			 + (sG bitShift:shiftGreen)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6564
			 + (sB bitShift:shiftBlue).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6565
		fixColors at:dstIdx put:(Color colorId:(pixel)).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6566
		dstIdx := dstIdx + 1
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6567
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6568
	]
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6569
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6570
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6571
    ^ self
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6572
	asFloydSteinbergDitheredDepth8FormOn:aDevice
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6573
	colors:fixColors
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6574
	nRed:nRed nGreen:nGreen nBlue:nBlue
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  6575
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6576
    "Created: 14.6.1996 / 17:23:52 / cg"
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  6577
    "Modified: 23.6.1997 / 15:22:36 / cg"
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6578
!
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6579
5919
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6580
compressColorMap
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6581
    "calculates a new color map for the image, using only used colors"
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6582
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6583
    |depth newColorMap usedColors oldToNew oldBits newBits tmpBits sortBlockForColors|
5919
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6584
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6585
    depth := self depth.
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6586
    usedColors := self realUsedColors.
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6587
    sortBlockForColors := [:a :b |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6588
	    a redByte == b redByte ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6589
		a greenByte == b greenByte ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6590
		    a blueByte < b blueByte
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6591
		] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6592
		    a greenByte < b greenByte
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6593
		]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6594
	    ] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6595
		a redByte < b redByte
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6596
	    ]
5919
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6597
      ].
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6598
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6599
    "/ translation table
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6600
    oldToNew := ByteArray new:(1 bitShift:depth).
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6601
    newColorMap := usedColors asArray.
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6602
    newColorMap sort:sortBlockForColors.
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6603
    self colorMap notNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6604
	self colorMap asArray keysAndValuesDo:[:oldIdx :clr |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6605
	    |newPixel|
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6606
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6607
	    (usedColors includes:clr) ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6608
		newPixel := newColorMap indexOf:clr.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6609
		oldToNew at:oldIdx put:newPixel-1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6610
	    ]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6611
	].
5919
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6612
    ].
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6613
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6614
    oldBits := self bits.
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6615
    newBits := ByteArray new:(oldBits size).
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6616
    depth ~~ 8 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6617
	"/ expand/compress can only handle 8bits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6618
	tmpBits := ByteArray uninitializedNew:(self width*self height).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6619
	oldBits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6620
	    expandPixels:depth
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6621
	    width:self width
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6622
	    height:self height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6623
	    into:tmpBits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6624
	    mapping:oldToNew.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6625
	tmpBits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6626
	    compressPixels:depth
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6627
	    width:self width
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6628
	    height:self height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6629
	    into:newBits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6630
	    mapping:nil
5919
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6631
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6632
	oldBits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6633
	    expandPixels:depth
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6634
	    width:self width
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6635
	    height:self height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6636
	    into:newBits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6637
	    mapping:oldToNew.
5919
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6638
    ].
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6639
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6640
    self bits:newBits.
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6641
    self colorMap:newColorMap.
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6642
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6643
    "Created: / 17-07-2012 / 12:13:18 / anwild"
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6644
!
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6645
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6646
rgbImageAsFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6647
    "convert am rgb image to a device-form on aDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6648
     Return the device-form."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6649
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6650
    |visual|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6651
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6652
    visual := aDevice visualType.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6653
    (visual == #StaticGray) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6654
	^ self asGrayFormOn:aDevice
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6655
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6656
    (visual == #TrueColor) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6657
	^ self rgbImageAsTrueColorFormOn:aDevice
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6658
    ].
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6659
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6660
    "/ PseudoColor conversion also works for StaticColor, GrayScale
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6661
    "/ and DirectColor displays; although possibly with suboptimal results
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6662
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6663
    ^ self rgbImageAsPseudoFormOn:aDevice
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6664
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6665
    "Modified: 14.6.1996 / 19:30:06 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6666
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6667
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6668
rgbImageAsPseudoFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6669
    "return a pseudocolor form from the rgb-picture"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6670
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6671
    |n     "{ Class: SmallInteger }"
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6672
     depth "{ Class: SmallInteger }"
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6673
     palette f|
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6674
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6675
    (depth := self depth) <= 8 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6676
	"/ simulate it via a temporary palette image
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6677
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6678
	palette := Array new:(1 bitShift:depth).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6679
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6680
	n := (1 bitShift:depth)-1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6681
	0 to:n do:[:pixelValue |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6682
	    palette at:(pixelValue+1) put:(self colorFromValue:pixelValue)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6683
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6684
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6685
	self setColorMap:palette.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6686
	photometric := #palette.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6687
	f := self paletteImageAsPseudoFormOn:aDevice.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6688
	self setColorMap:nil.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6689
	photometric := #rgb.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6690
	^ f
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6691
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6692
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6693
    ^ self subclassResponsibility
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6694
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6695
    "Modified: 8.6.1996 / 10:58:25 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6696
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6697
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6698
rgbImageAsTrueColorFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6699
    "return a truecolor form from the rgb-picture."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6700
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  6701
    |bestFormat usedDeviceDepth usedDeviceBitsPerPixel
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6702
     form|
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6703
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6704
    bestFormat := self bestSupportedImageFormatFor:aDevice.
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  6705
    usedDeviceDepth := bestFormat at:#depth.
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  6706
    usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6707
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6708
    "/ 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
  6709
    usedDeviceBitsPerPixel == 15 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6710
	usedDeviceBitsPerPixel := 16
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  6711
    ].
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  6712
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6713
    "/
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6714
    "/ only the trivial case, where the depths match
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6715
    "/ is handled here; conversions are supposed to
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6716
    "/ be done in concrete subclasses (see D24Image)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6717
    "/
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6718
    self bitsPerPixel == usedDeviceBitsPerPixel ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6719
	"/ kludge - convert to a deep image first, then to a form.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6720
	^ ((Image implementorForDepth:usedDeviceBitsPerPixel) fromImage:self) asFormOn:aDevice
5126
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  6721
"/        '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
  6722
"/        ^ self asMonochromeFormOn:aDevice
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  6723
    ].
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  6724
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  6725
    form := Form width:width height:height depth:usedDeviceDepth onDevice:aDevice.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6726
    form isNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6727
	'Image [warning]: display bitmap creation failed' errorPrintCR.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6728
	^ nil
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6729
    ].
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6730
    form initGC.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6731
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6732
    form
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6733
	copyBitsFrom:self bits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6734
	bitsPerPixel:usedDeviceBitsPerPixel
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6735
	depth:usedDeviceDepth
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6736
	padding:8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6737
	width:width height:height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6738
	x:0 y:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6739
	toX:0 y:0.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6740
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6741
    ^ form
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6742
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  6743
    "Modified: / 27-05-2007 / 13:44:26 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6744
! !
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
!Image methodsFor:'copying'!
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
postCopy
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  6749
    "redefined to also copy the pixels and the colorMap
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  6750
     and clear out any device handles in the copy."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  6751
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6752
    bytes := bytes copy.
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  6753
    (colorMap isNil or:[colorMap isKindOf:Colormap]) ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6754
	colorMap := MappedPalette withColors:colorMap.
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  6755
    ] ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6756
	colorMap := colorMap copy.
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  6757
    ].
1963
ab2d96e4e140 care for masks in copy/copySubImage;
tz
parents: 1962
diff changeset
  6758
    device := deviceForm := monoDeviceForm := fullColorDeviceForm := nil.
ab2d96e4e140 care for masks in copy/copySubImage;
tz
parents: 1962
diff changeset
  6759
    mask := mask copy.
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  6760
    maskedPixelsAre0 := false.
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  6761
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  6762
    "Modified: / 22.8.1998 / 11:27:09 / cg"
2947
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6763
!
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6764
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6765
skipInstvarIndexInDeepCopy:index
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6766
    "a helper for deepCopy; only indices for which this method returns
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6767
     false are copied in a deep copy."
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6768
5956
c46b8003e817 class: Image
Stefan Vogel <sv@exept.de>
parents: 5926
diff changeset
  6769
    index == 17 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6770
	^ true "/ skip device
5956
c46b8003e817 class: Image
Stefan Vogel <sv@exept.de>
parents: 5926
diff changeset
  6771
    ].
c46b8003e817 class: Image
Stefan Vogel <sv@exept.de>
parents: 5926
diff changeset
  6772
    index == 18 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6773
	^ true "/ skip deviceForm
5956
c46b8003e817 class: Image
Stefan Vogel <sv@exept.de>
parents: 5926
diff changeset
  6774
    ].
c46b8003e817 class: Image
Stefan Vogel <sv@exept.de>
parents: 5926
diff changeset
  6775
    index == 19 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6776
	^ true "/ skip monoDeviceForm
5956
c46b8003e817 class: Image
Stefan Vogel <sv@exept.de>
parents: 5926
diff changeset
  6777
    ].
c46b8003e817 class: Image
Stefan Vogel <sv@exept.de>
parents: 5926
diff changeset
  6778
    index == 20 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6779
	^ true "/ skip fullColorDeviceForm
2947
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6780
    ].
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6781
    ^ false
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6782
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6783
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6784
!Image methodsFor:'displaying'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6785
1737
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  6786
asImage
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  6787
    "ST-80 compatibility
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  6788
    "
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  6789
    ^ self
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  6790
!
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  6791
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6792
displayFilledOn:aGC
759
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  6793
    "display the receiver as an opaque image.
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6794
     This allows Images to be wrapped by a FillingWrapper"
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6795
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6796
    aGC displayOpaqueForm:self x:0 y:0.
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6797
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6798
    "Created: 29.5.1996 / 10:34:18 / cg"
759
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  6799
    "Modified: 29.5.1996 / 10:52:36 / cg"
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6800
!
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6801
3865
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6802
displayOn:aGC x:x y:y
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6803
    "draw the receiver in the graphicsContext, aGC.
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6804
     Smalltalk-80 compatibility"
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6805
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6806
    aGC displayForm:self x:x y:y.
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6807
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6808
    "Modified: 23.4.1996 / 11:12:31 / cg"
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6809
    "Created: 12.5.1996 / 20:14:31 / cg"
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6810
!
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6811
3729
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6812
displayOn:aGC x:x y:y opaque:opaque
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6813
    "draw the receiver in the graphicsContext, aGC.
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6814
     Smalltalk-80 compatibility"
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6815
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6816
    opaque ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6817
	self displayOpaqueOn:aGC x:x y:y .
3729
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6818
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6819
	self displayOn:aGC x:x y:y .
3729
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6820
    ].
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6821
!
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6822
3379
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6823
displayOpaqueOn:aGC at:aPoint
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6824
    "draw the receiver in the graphicsContext, aGC.
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6825
     Smalltalk-80 compatibility"
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6826
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6827
    self displayOpaqueOn:aGC x:aPoint x y:aPoint y.
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6828
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6829
    "Modified: 12.5.1996 / 20:16:38 / cg"
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6830
!
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6831
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6832
displayOpaqueOn:aGC x:x y:y
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6833
    "draw the receiver in the graphicsContext, aGC.
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6834
     Smalltalk-80 compatibility"
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6835
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6836
    aGC displayOpaqueForm:self x:x y:y.
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6837
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6838
    "Modified: 23.4.1996 / 11:12:31 / cg"
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6839
    "Created: 22.10.1996 / 16:35:49 / cg"
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6840
!
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6841
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6842
displayStrokedOn:aGC
759
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  6843
    "display the receiver as an non opaque image.
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6844
     This allows Images to be wrapped by a StrokingWrapper"
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6845
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6846
    aGC displayForm:self x:0 y:0.
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6847
759
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  6848
    "Created: 29.5.1996 / 10:34:18 / cg"
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  6849
    "Modified: 29.5.1996 / 10:52:30 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6850
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6851
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6852
!Image methodsFor:'dither helpers'!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6853
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6854
burkesDitheredMonochromeBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6855
    "return the bitmap for a dithered monochrome bitmap from the image.
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6856
     Works for any source depths / photometric.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6857
     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
  6858
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6859
    |dstIndex        "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6860
     nextDst         "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6861
     bytesPerMonoRow "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6862
     monoBits greyValues
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6863
     errorArray
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6864
     errorArray1
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6865
     e t
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6866
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6867
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6868
     bitCnt          "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6869
     byte            "{Class: SmallInteger }"
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  6870
     grey|
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6871
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6872
    self depth > 12 ifTrue:[
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6873
        ^ self floydSteinbergDitheredMonochromeBits
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6874
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6875
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6876
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6877
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6878
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6879
    bytesPerMonoRow := (w + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6880
    monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6881
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6882
    errorArray := Array new:(w+4).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6883
    errorArray1 := Array new:(w+4) withAll:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6884
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6885
    dstIndex := 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6886
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6887
    "/ 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
  6888
    "/ use table-value in loop
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6889
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6890
    greyValues := self greyMapForRange:(255*1024).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6891
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6892
    0 to:(h-1) do:[:y |
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6893
        nextDst := dstIndex + bytesPerMonoRow.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6894
        byte := 0.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6895
        bitCnt := 8.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6896
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6897
        t := errorArray.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6898
        errorArray := errorArray1.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6899
        errorArray1 := t.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6900
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6901
        errorArray1 atAllPut:0.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6902
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6903
        self valuesAtY:y from:0 to:(w-1) do:[:x :pixel |
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6904
            |eP "{Class: SmallInteger }"
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6905
             eD
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6906
             eI "{Class: SmallInteger }"
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6907
             xE "{Class: SmallInteger }"
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6908
             xN "{Class: SmallInteger }" |
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6909
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6910
            "/ get the colors grey value [0 .. 1]
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6911
            grey := greyValues at:(pixel + 1).
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6912
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6913
            "/ adjust error
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6914
            xE := x + 2 + 1.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6915
            grey := (grey + (errorArray at:xE)).
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6916
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6917
            byte := byte bitShift:1.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6918
            grey > (127*1024) ifTrue:[
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6919
                byte := byte bitOr:1.      "/ white
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6920
                e := grey - (255*1024)
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6921
            ] ifFalse:[
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6922
                e := grey                  "/ black
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6923
            ].
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6924
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6925
            e ~= 0 ifTrue:[
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6926
                "/ distribute the error:
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6927
                "/                  XX  8  4
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6928
                "/             2  4  8  4  2
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6929
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6930
                eD := e.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6931
                eI := e // 32.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6932
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6933
                eP := eI * 8. eD := eD - eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6934
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6935
                xN := xE + 1.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6936
                errorArray at:xN put:(errorArray at:xN) + eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6937
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6938
                eD := eD - eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6939
                errorArray1 at:xE put:(errorArray1 at:xE) + eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6940
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6941
                eP := eI * 4. eD := eD - eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6942
                xN := xE + 2.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6943
                errorArray at:xN put:(errorArray at:xN) + eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6944
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6945
                eD := eD - eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6946
                xN := xE - 1.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6947
                errorArray1 at:xN put:(errorArray1 at:xN) + eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6948
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6949
                eD := eD - eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6950
                xN := xE + 1.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6951
                errorArray1 at:xN put:(errorArray1 at:xN) + eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6952
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6953
                eP := eI * 2. eD := eD - eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6954
                xN := xE - 2.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6955
                errorArray1 at:xN put:(errorArray1 at:xN) + eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6956
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6957
                "/ eD := eD.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6958
                xN := xE + 2.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6959
                errorArray1 at:xN put:(errorArray1 at:xN) + eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6960
            ].
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6961
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6962
            bitCnt := bitCnt - 1.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6963
            bitCnt == 0 ifTrue:[
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6964
                monoBits at:dstIndex put:byte.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6965
                dstIndex := dstIndex + 1.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6966
                byte := 0.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6967
                bitCnt := 8.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6968
            ].
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6969
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6970
        ].
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6971
        bitCnt ~~ 8 ifTrue:[
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6972
            byte := byte bitShift:bitCnt.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6973
            monoBits at:dstIndex put:byte.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6974
        ].
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6975
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6976
        dstIndex := nextDst.
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
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6979
    ^ monoBits
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
    "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
  6982
    "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
  6983
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6984
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6985
floydSteinbergDitheredDepth8BitsColors:colors
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6986
    "return a floyd-steinberg dithered bitmap from the receiver picture,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6987
     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
  6988
     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
  6989
     (which need not be a colorCubes colors)."
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6990
3157
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6991
    ^ self floydSteinbergDitheredDepth8BitsColors:colors map:nil
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6992
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6993
!
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6994
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6995
floydSteinbergDitheredDepth8BitsColors:colors map:aMapOrNil
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6996
    "return a floyd-steinberg dithered bitmap from the receiver picture,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6997
     which must be a depth-24 image.
3157
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6998
     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
  6999
     (which need not be a colorCubes colors)."
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  7000
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7001
    |pseudoBits
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7002
     ditherRGBBytes ditherColors
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7003
     w       "{Class: SmallInteger }"
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7004
     h       "{Class: SmallInteger }"
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7005
     index   "{Class: SmallInteger }"
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7006
     ditherIds failed lastColor qScramble
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7007
     clrLookup lookupPos
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7008
     error clr|
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7009
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7010
    self depth ~~ 24 ifTrue:[^ nil].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7011
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7012
    "/ collect valid ditherColors ...
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7013
    aMapOrNil isNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7014
	ditherColors := colors select:[:clr | clr notNil].
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7015
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7016
	ditherColors := colors
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7017
    ].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7018
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7019
    "/ ... and sort by manhatten distance from black
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7020
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7021
    qScramble := #(
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7022
		"/  2rX00X00X00X00
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7023
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7024
		    2r000000000000    "/ 0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7025
		    2r000000000100    "/ 1
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7026
		    2r000000100000    "/ 2
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7027
		    2r000000100100    "/ 3
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7028
		    2r000100000000    "/ 4
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7029
		    2r000100000100    "/ 5
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7030
		    2r000100100000    "/ 6
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7031
		    2r000100100100    "/ 7
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7032
		    2r100000000000    "/ 8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7033
		    2r100000000100    "/ 9
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7034
		    2r100000100000    "/ a
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7035
		    2r100000100100    "/ b
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7036
		    2r100100000000    "/ c
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7037
		    2r100100000100    "/ d
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7038
		    2r100100100000    "/ e
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7039
		    2r100100100100    "/ f
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7040
		  ).
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7041
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7042
    ditherColors := ditherColors sort:[:a :b |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7043
				|cr "{Class: SmallInteger }"
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7044
				 cg "{Class: SmallInteger }"
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7045
				 cb "{Class: SmallInteger }"
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7046
				 i1 "{Class: SmallInteger }"
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7047
				 i2 "{Class: SmallInteger }"|
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7048
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7049
				cr := a redByte.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7050
				cg := a greenByte.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7051
				cb := a blueByte.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7052
				i1 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7053
				i1 := i1 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7054
				i1 := i1 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7055
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7056
				cr := b redByte.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7057
				cg := b greenByte.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7058
				cb := b blueByte.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7059
				i2 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7060
				i2 := i2 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7061
				i2 := i2 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7062
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7063
				i1 < i2
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7064
		    ].
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7065
    aMapOrNil isNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7066
	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
  7067
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7068
	ditherIds := aMapOrNil asByteArray
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7069
    ].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7070
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7071
    "/ 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
  7072
    "/ to the position in the colorList
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7073
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7074
    clrLookup := ByteArray new:(4096).
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7075
    index := 0.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7076
    ditherColors keysAndValuesDo:[:clrPosition :clr |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7077
	|r g b i|
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7078
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7079
	r := clr redByte.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7080
	g := clr greenByte.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7081
	b := clr blueByte.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7082
	i := qScramble at:((r bitShift:-4) bitAnd:16r0F) + 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7083
	i := i + ((qScramble at:((g bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7084
	i := i + ((qScramble at:((b bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7085
	lookupPos := i.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7086
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7087
	[index < lookupPos] whileTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7088
	    clrLookup at:(index+1) put:(clrPosition-1-1).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7089
	    index := index + 1
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7090
	]
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7091
    ].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7092
    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
  7093
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7094
"/    [index <= (4095)] whileTrue:[
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7095
"/        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
  7096
"/        index := index + 1.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7097
"/    ].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7098
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7099
    "/ collect ditherColor components
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7100
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7101
    lastColor := ditherColors size.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7102
    ditherIds := ByteArray uninitializedNew:lastColor.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7103
    ditherRGBBytes := ByteArray uninitializedNew:(lastColor * 3).
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7104
    index := 1.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7105
    1 to:lastColor do:[:pix |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7106
	clr := ditherColors at:pix.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7107
	ditherRGBBytes at:index put:(clr redByte).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7108
	ditherRGBBytes at:index+1 put:(clr greenByte).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7109
	ditherRGBBytes at:index+2 put:(clr blueByte).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7110
	aMapOrNil isNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7111
	    ditherIds at:pix put:clr colorId.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7112
	] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7113
	    ditherIds at:pix put:(aMapOrNil at:pix).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7114
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7115
	index := index + 3.
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7116
    ].
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
    pseudoBits := ByteArray uninitializedNew:(width * height).
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7119
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7120
    w := width + 2.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7121
    error := ByteArray uninitializedNew:w*(3*2).
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7122
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7123
    w := width.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7124
    h := height.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7125
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7126
    failed := true.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7127
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7128
%{
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7129
    int __x, __y;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7130
    int __eR, __eG, __eB;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7131
    unsigned char *srcP, *dstP;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7132
    unsigned char *idP;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7133
    unsigned char *dp;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7134
    unsigned char *__clrLookup;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7135
    short *errP, *eP;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7136
    int __fR, __fG, __fB;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7137
    int iR, iG, iB;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7138
    int idx;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7139
    int __w = __intVal(w);
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7140
    int __h = __intVal(h);
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7141
    int __nColors = __intVal(lastColor);
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7142
    int __wR = -1, __wG, __wB;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7143
    static int __qScramble[16] = {
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7144
		    0x000 /* 2r000000000000    0 */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7145
		    0x004 /* 2r000000000100    1 */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7146
		    0x020 /* 2r000000100000    2 */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7147
		    0x024 /* 2r000000100100    3 */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7148
		    0x100 /* 2r000100000000    4 */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7149
		    0x104 /* 2r000100000100    5 */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7150
		    0x120 /* 2r000100100000    6 */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7151
		    0x124 /* 2r000100100100    7 */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7152
		    0x800 /* 2r100000000000    8 */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7153
		    0x804 /* 2r100000000100    9 */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7154
		    0x820 /* 2r100000100000    a */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7155
		    0x824 /* 2r100000100100    b */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7156
		    0x900 /* 2r100100000000    c */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7157
		    0x904 /* 2r100100000100    d */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7158
		    0x920 /* 2r100100100000    e */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7159
		    0x924 /* 2r100100100100    f */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7160
		  };
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7161
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7162
    if (__isByteArrayLike(__INST(bytes))
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7163
     && __isByteArray(pseudoBits)
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7164
     && __isByteArray(ditherRGBBytes)
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7165
     && __isByteArray(ditherIds)
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7166
     && __isByteArray(clrLookup)
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7167
     && __isByteArray(error)) {
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7168
	failed = false;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7169
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7170
	srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7171
	dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7172
	idP = __ByteArrayInstPtr(ditherIds)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7173
	__clrLookup = __ByteArrayInstPtr(clrLookup)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7174
	errP = (short *) __ByteArrayInstPtr(error)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7175
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7176
	/*
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7177
	 * clear error accumulator
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7178
	 */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7179
	eP = errP;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7180
	bzero(eP, (__w+2) * 2 * 3);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7181
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7182
	for (__y=__h; __y>0; __y--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7183
	    __eR = __eG = __eB = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7184
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7185
	    eP = &(errP[3]);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7186
	    __eR = eP[0];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7187
	    __eG = eP[1];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7188
	    __eB = eP[2];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7189
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7190
	    for (__x=__w; __x>0; __x--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7191
		int __want;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7192
		int pix;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7193
		int __wantR, __wantG, __wantB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7194
		int idx;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7195
		int tR, tG, tB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7196
		int nR, nG, nB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7197
		int dR, dG, dB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7198
		int minDelta, bestIdx;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7199
		int cnt;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7200
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7201
		__wantR = *srcP++;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7202
		__wantG = *srcP++;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7203
		__wantB = *srcP++;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7204
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7205
		/*
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7206
		 * wR, wG and wB is the wanted r/g/b value;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7207
		 */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7208
		__wantR = __wantR + __eR;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7209
		__wantG = __wantG + __eG;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7210
		__wantB = __wantB + __eB;
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7211
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7212
#define RED_SCALE 30
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7213
#define GREEN_SCALE 59
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7214
#define BLUE_SCALE 11
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7215
#define GOOD_DELTA 30
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7216
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7217
#define xRED_SCALE 1
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7218
#define xGREEN_SCALE 1
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7219
#define xBLUE_SCALE 1
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7220
#define xGOOD_DELTA 3
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7221
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7222
#define FAST_LOOKUP
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7223
/* #define ONE_SHOT */
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7224
#define NPROBE 8
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
#ifndef FAST_LOOKUP
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7227
		if ((__wantR == __wR)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7228
		 && (__wantG == __wG)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7229
		 && (__wantB == __wB)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7230
		    /*
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7231
		     * same color again - reuse last bestMatch
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7232
		     */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7233
		} else
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7234
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7235
		{
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7236
		    __wR = __wantR;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7237
		    __wG = __wantG;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7238
		    __wB = __wantB;
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7239
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7240
#ifdef FAST_LOOKUP
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7241
		    if(__wR > 255) __wR = 255;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7242
		    else if (__wR < 0) __wR = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7243
		    if(__wG > 255) __wG = 255;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7244
		    else if (__wG < 0) __wG = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7245
		    if(__wB > 255) __wB = 255;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7246
		    else if (__wB < 0) __wB = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7247
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7248
		    {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7249
			int lookupIndex;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7250
			int idx, idx0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7251
			int d, delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7252
			unsigned char *dp0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7253
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7254
			dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7255
			lookupIndex =    __qScramble[((__wR & 0xF0)>>4)];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7256
			lookupIndex |=   __qScramble[((__wG & 0xF0)>>4)] >> 1;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7257
			lookupIndex |=   __qScramble[((__wB & 0xF0)>>4)] >> 2;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7258
			idx = bestIdx =__clrLookup[lookupIndex];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7259
			dp += (idx+idx+idx);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7260
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7261
			/* try color at lookupIndex */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7262
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7263
			d = dp[0];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7264
			delta = (__wR - d) * RED_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7265
			if (delta < 0) delta = -delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7266
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7267
			d = dp[1];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7268
			if (__wG > d)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7269
			    delta += (__wG - d) * GREEN_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7270
			else
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7271
			    delta += (d - __wG) * GREEN_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7272
			d = dp[2];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7273
			if (__wB > d)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7274
			    delta += (__wB - d) * BLUE_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7275
			else
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7276
			    delta += (d - __wB) * BLUE_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7277
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7278
			if (delta <= GOOD_DELTA) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7279
			    goto foundBest;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7280
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7281
			minDelta = delta;
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7282
# ifndef ONE_SHOT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7283
			idx0 = idx; dp0 = dp;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7284
			cnt = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7285
			while ((++cnt <= NPROBE) && (idx > 0)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7286
			    /* try previous color(s) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7287
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7288
			    idx--; dp -= 3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7289
			    d = dp[0];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7290
			    delta = (__wR - d) * RED_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7291
			    if (delta < 0) delta = -delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7292
			    d = dp[1];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7293
			    if (__wG > d)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7294
				delta += (__wG - d) * GREEN_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7295
			    else
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7296
				delta += (d - __wG) * GREEN_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7297
			    d = dp[2];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7298
			    if (__wB > d)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7299
				delta += (__wB - d) * BLUE_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7300
			    else
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7301
				delta += (d - __wB) * BLUE_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7302
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7303
			    if (delta < minDelta) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7304
				bestIdx = idx;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7305
				if (delta <= GOOD_DELTA) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7306
				    goto foundBest;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7307
				}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7308
				minDelta = delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7309
			    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7310
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7311
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7312
			idx = idx0; dp = dp0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7313
			cnt = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7314
			while ((++cnt <= NPROBE) && (++idx < __nColors)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7315
			    /* try next color */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7316
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7317
			    dp += 3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7318
			    d = dp[0];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7319
			    delta = (__wR - d) * RED_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7320
			    if (delta < 0) delta = -delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7321
			    d = dp[1];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7322
			    if (__wG > d)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7323
				delta += (__wG - d) * GREEN_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7324
			    else
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7325
				delta += (d - __wG) * GREEN_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7326
			    d = dp[2];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7327
			    if (__wB > d)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7328
				delta += (__wB - d) * BLUE_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7329
			    else
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7330
				delta += (d - __wB) * BLUE_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7331
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7332
			    if (delta < minDelta) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7333
				bestIdx = idx;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7334
				if (delta <= GOOD_DELTA) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7335
				    goto foundBest;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7336
				}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7337
				minDelta = delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7338
			    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7339
			}
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7340
# endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7341
		    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7342
	foundBest: ;
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7343
#else
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7344
/*
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7345
		    if(__wR > 255) __wR = 255;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7346
		    else if (__wR < 0) __wR = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7347
		    if(__wG > 255) __wG = 255;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7348
		    else if (__wG < 0) __wG = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7349
		    if(__wB > 255) __wB = 255;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7350
		    else if (__wB < 0) __wB = 0;
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7351
*/
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7352
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7353
		    /* find the best matching color */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7354
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7355
		    minDelta = 99999;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7356
		    bestIdx = -1;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7357
		    dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7358
		    for (idx = 0; idx<__nColors; idx++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7359
			int d, delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7360
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7361
			d = dp[0];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7362
			delta = (__wR - d) * RED_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7363
			if (delta < 0) delta = -delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7364
			if (delta < minDelta) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7365
			    d = dp[1];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7366
			    if (__wG > d)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7367
				delta += (__wG - d) * GREEN_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7368
			    else
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7369
				delta += (d - __wG) * GREEN_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7370
			    if (delta < minDelta) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7371
				d = dp[2];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7372
				if (__wB > d)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7373
				    delta += (__wB - d) * BLUE_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7374
				else
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7375
				    delta += (d - __wB) * BLUE_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7376
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7377
				if (delta < minDelta) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7378
				    bestIdx = idx;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7379
				    if (delta <= GOOD_DELTA) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7380
					break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7381
				    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7382
				    minDelta = delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7383
				}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7384
			    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7385
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7386
			dp += 3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7387
		    }
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7388
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7389
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7390
		dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7391
		dp += bestIdx * 3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7392
		dR = dp[0];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7393
		dG = dp[1];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7394
		dB = dp[2];
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7395
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7396
/*
4725
c8896df7bd3f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4717
diff changeset
  7397
console_fprintf(stderr, "want: %d/%d/%d (%d/%d/%d) got: %d/%d/%d\n",
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7398
		__wantR, __wantG, __wantB,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7399
		__wR, __wG, __wB,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7400
		dR, dG, dB);
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7401
*/
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7402
		/*
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7403
		 * store the corresponding dither colors colorId
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7404
		 */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7405
		*dstP++ = idP[bestIdx];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7406
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7407
		/*
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7408
		 * the new error & distribute the error
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7409
		 */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7410
		__eR = __wantR - dR;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7411
		if (__eR) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7412
		    tR = __eR >> 4;  /* 16th of error */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7413
		    nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7414
		    eP[0] = tR*5;         /* 5/16th for (x / y+1) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7415
		    eP[-3] = tR*3;        /* 3/16th for (x-1 / y+1) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7416
		    eP[3] = __eR - (tR*15);  /* 1/16th for (x+1 / y+1) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7417
		    __eR = nR;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7418
		} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7419
		    __eR = eP[3];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7420
		    eP[0] = eP[-3] = eP[3] = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7421
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7422
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7423
		__eG = __wantG - dG;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7424
		if (__eG) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7425
		    tG = __eG >> 4;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7426
		    nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7427
		    eP[1] = tG*5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7428
		    eP[-2] = tG*3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7429
		    eP[4] = __eG - (tG*15);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7430
		    __eG = nG;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7431
		} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7432
		    __eG = eP[4];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7433
		    eP[1] = eP[-2] = eP[4] = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7434
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7435
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7436
		__eB = __wantB - dB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7437
		if (__eB) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7438
		    tB = __eB >> 4;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7439
		    nB = eP[5] + (tB * 7);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7440
		    eP[2] = tB*5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7441
		    eP[-1] = tB*3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7442
		    eP[5] = __eB - (tB*15);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7443
		    __eB = nB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7444
		} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7445
		    __eB = eP[5];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7446
		    eP[2] = eP[-1] = eP[5] = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7447
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7448
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7449
		eP += 3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7450
	    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7451
	}
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7452
    }
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7453
%}.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7454
    failed ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7455
	self primitiveFailed.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7456
	^ nil
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
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7459
    ^ pseudoBits
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  7460
!
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  7461
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7462
floydSteinbergDitheredDepth8BitsColors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  7463
    "return a floyd-steinberg dithered bitmap from the receiver picture,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7464
     which must be a depth-8 image.
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  7465
     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
  7466
     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
  7467
     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
  7468
     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
  7469
     Color class.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7470
     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
  7471
     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
  7472
     for example to create dithered Depth4Images from Depth8Images."
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7473
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7474
    |pseudoBits
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7475
     rgbBytes
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7476
     w       "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7477
     h       "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7478
     index   "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7479
     fixR    "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7480
     fixG    "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7481
     fixB    "{Class: SmallInteger }"
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7482
     fixGfixB
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7483
     fixIds failed map lastColor
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7484
     rgbIDX  "{Class: SmallInteger }"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7485
     idxAndErrRBytes idxAndErrGBytes idxAndErrBBytes
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7486
     error clr|
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7487
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  7488
    self depth ~~ 8 ifTrue:[^ nil].
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  7489
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7490
    fixR := nRed.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7491
    fixR == 0 ifTrue:[ ^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7492
    fixG := nGreen.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7493
    fixG == 0 ifTrue:[ ^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7494
    fixB := nBlue.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7495
    fixB == 0 ifTrue:[ ^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7496
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7497
    "/ simple check
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7498
    (fixR * fixG * fixB) ~~ fixColors size ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7499
	self error:'invalid color array passed'.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7500
	^ nil
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7501
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7502
    fixIds := (fixColors asArray collect:[:clr | clr colorId]) asByteArray.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7503
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7504
    "/
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7505
    "/ collect color components as integer values (for integer arithmetic)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7506
    "/
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7507
    rgbBytes := ByteArray uninitializedNew:256 * 3.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7508
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7509
    index := 1.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7510
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7511
    photometric == #palette ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7512
	lastColor := colorMap size - 1
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7513
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7514
	lastColor := 255.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7515
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7516
    0 to:lastColor do:[:pix |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7517
	clr := self colorFromValue:pix.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7518
	rgbBytes at:index put:(clr redByte).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7519
	rgbBytes at:index+1 put:(clr greenByte).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7520
	rgbBytes at:index+2 put:(clr blueByte).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7521
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7522
	index := index + 3.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7523
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7524
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7525
    pseudoBits := ByteArray uninitializedNew:(width * height).
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7526
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7527
    w := width + 2.
1636
c30f6644666e dont use bcopy in #floydSteinbergDitheredDepth8BitsColors
Claus Gittinger <cg@exept.de>
parents: 1630
diff changeset
  7528
    error := ByteArray new:w*(3*2).
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7529
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7530
    w := width.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7531
    h := height.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7532
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7533
    idxAndErrRBytes := ByteArray uninitializedNew:256*2.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7534
    idxAndErrGBytes := ByteArray uninitializedNew:256*2.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7535
    idxAndErrBBytes := ByteArray uninitializedNew:256*2.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7536
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7537
    fixGfixB := fixG * fixB.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7538
    index := 1.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7539
    0 to:255 do:[:i |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7540
	rgbIDX := (i * (fixR-1) + 128) // 255. "red index rounded"
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7541
	idxAndErrRBytes at:index put:(rgbIDX * fixGfixB).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7542
	idxAndErrRBytes at:index+1 put:i - (rgbIDX * 255 // (fixR-1)) + 128.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7543
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7544
	rgbIDX := (i * (fixG-1) + 128) // 255. "green index rounded"
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7545
	idxAndErrGBytes at:index put:(rgbIDX * fixB).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7546
	idxAndErrGBytes at:index+1 put:i - (rgbIDX * 255 // (fixG-1)) + 128.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7547
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7548
	rgbIDX := (i * (fixB-1) + 128) // 255. "blue index rounded"
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7549
	idxAndErrBBytes at:index put:(rgbIDX ).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7550
	idxAndErrBBytes at:index+1 put:i - (rgbIDX * 255 // (fixB-1)) + 128.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7551
	index := index + 2.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7552
    ].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7553
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7554
    failed := true.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7555
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7556
%{
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7557
    int __x, __y;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7558
    int __eR, __eG, __eB;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7559
    unsigned char *srcP, *dstP;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7560
    unsigned char *rgbP;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7561
    unsigned char *idP;
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7562
    unsigned char *__idxAndErrRBytes, *__idxAndErrGBytes, *__idxAndErrBBytes;
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7563
    short *errP, *eP;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7564
    int idx;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7565
    int __w = __intVal(w);
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7566
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7567
    if (__isByteArrayLike(__INST(bytes))
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7568
     && __isByteArray(pseudoBits)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7569
     && __isByteArray(rgbBytes)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7570
     && __isByteArray(fixIds)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7571
     && __isByteArray(error)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7572
     && __bothSmallInteger(fixR, fixG)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7573
     && __isSmallInteger(fixB)) {
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7574
	failed = false;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7575
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7576
	srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7577
	dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7578
	rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7579
	idP = __ByteArrayInstPtr(fixIds)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7580
	__idxAndErrRBytes = __ByteArrayInstPtr(idxAndErrRBytes)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7581
	__idxAndErrGBytes = __ByteArrayInstPtr(idxAndErrGBytes)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7582
	__idxAndErrBBytes = __ByteArrayInstPtr(idxAndErrBBytes)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7583
	errP = (short *) __ByteArrayInstPtr(error)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7584
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7585
	eP = errP;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7586
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7587
	for (__y=__intVal(h); __y>0; __y--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7588
	    __eR = __eG = __eB = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7589
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7590
	    eP = &(errP[3]);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7591
	    __eR = eP[0];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7592
	    __eG = eP[1];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7593
	    __eB = eP[2];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7594
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7595
	    for (__x=__w; __x>0; __x--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7596
		int __want;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7597
		int pix;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7598
		int idx;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7599
		int tR, tG, tB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7600
		int nR, nG, nB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7601
		int iRGB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7602
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7603
		pix = *srcP++;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7604
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7605
		/*
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7606
		 * wR, wG and wB is the wanted r/g/b value;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7607
		 */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7608
		pix = pix+pix+pix;  /* pix * 3 */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7609
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7610
		/*
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7611
		 * compute indexR/G/B and the new error:
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7612
		 */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7613
		__want = rgbP[pix]   + __eR;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7614
		if (__want > 255) __want = 255;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7615
		else if (__want < 0) __want = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7616
		__want += __want;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7617
		idx = __idxAndErrRBytes[__want];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7618
		__eR = __idxAndErrRBytes[__want+1];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7619
		__eR -= 128;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7620
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7621
		__want = rgbP[pix+1] + __eG;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7622
		if (__want > 255) __want = 255;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7623
		else if (__want < 0) __want = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7624
		__want += __want;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7625
		idx += __idxAndErrGBytes[__want];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7626
		__eG = __idxAndErrGBytes[__want+1];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7627
		__eG -= 128;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7628
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7629
		__want = rgbP[pix+2] + __eB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7630
		if (__want > 255) __want = 255;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7631
		else if (__want < 0) __want = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7632
		__want += __want;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7633
		idx += __idxAndErrBBytes[__want];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7634
		__eB = __idxAndErrBBytes[__want+1];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7635
		__eB -= 128;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7636
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7637
		/*
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7638
		 * store the corresponding dither colors colorId
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7639
		 */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7640
		*dstP++ = idP[idx];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7641
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7642
		/*
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7643
		 * distribute the error
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7644
		 */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7645
		if (__eR) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7646
		    tR = __eR >> 4;  /* 16th of error */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7647
		    nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7648
		    eP[0] = tR*5;         /* 5/16th for (x / y+1) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7649
		    eP[-3] = tR*3;        /* 3/16th for (x-1 / y+1) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7650
		    eP[3] = __eR - (tR*15);  /* 1/16th for (x+1 / y+1) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7651
		    __eR = nR;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7652
		} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7653
		    __eR = eP[3];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7654
		    eP[0] = eP[-3] = eP[3] = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7655
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7656
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7657
		if (__eG) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7658
		    tG = __eG >> 4;  /* 16th of error */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7659
		    nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7660
		    eP[1] = tG*5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7661
		    eP[-2] = tG*3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7662
		    eP[4] = __eG - (tG*15);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7663
		    __eG = nG;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7664
		} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7665
		    __eG = eP[4];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7666
		    eP[1] = eP[-2] = eP[4] = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7667
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7668
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7669
		if (__eB) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7670
		    tB = __eB >> 4;  /* 16th of error */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7671
		    nB = eP[5] + (tB * 7);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7672
		    eP[2] = tB*5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7673
		    eP[-1] = tB*3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7674
		    eP[5] = __eB - (tB*15);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7675
		    __eB = nB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7676
		} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7677
		    __eB = eP[5];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7678
		    eP[2] = eP[-1] = eP[5] = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7679
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7680
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7681
		eP += 3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7682
	    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7683
	}
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7684
    }
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7685
%}.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7686
    failed ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7687
	self primitiveFailed.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7688
	^ nil
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7689
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7690
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7691
    ^ pseudoBits
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7692
!
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7693
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7694
floydSteinbergDitheredGrayBitsDepth:depth
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7695
    "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
  7696
     Works for any source depths / photometric,
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7697
     but possibly slow since each pixel is processed individually.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7698
     Redefined by some subclasses for more performance (D8Image/D24Image)"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7699
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7700
    |dstIndex        "{Class: SmallInteger }"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7701
     nextDst         "{Class: SmallInteger }"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7702
     bytesPerOutRow  "{Class: SmallInteger }"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7703
     outBits greyValues greyErrors greyPixels greyLevels
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7704
     errorArray
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7705
     nextErrorArray
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7706
     t
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7707
     w               "{Class: SmallInteger }"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7708
     h               "{Class: SmallInteger }"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7709
     bitCnt          "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7710
     byte            "{Class: SmallInteger }"
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7711
     grey
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7712
     eR eRB eB eLB |
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7713
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7714
    depth > 8 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7715
	self error:'unimplemented conversion'.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7716
	^ nil
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7717
    ].
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7718
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7719
    w := width.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7720
    h := height.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7721
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7722
    bytesPerOutRow := ((w * depth) + 7) // 8.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7723
    outBits := ByteArray uninitializedNew:(bytesPerOutRow * h).
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7724
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7725
    greyLevels := (1 bitShift:depth) - 1.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7726
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7727
    errorArray := Array new:w+2.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7728
    nextErrorArray := Array new:w+2.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7729
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7730
    nextErrorArray atAllPut:0.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7731
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7732
    dstIndex := 1.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7733
    bitCnt := 8.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7734
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7735
    self depth <= 12 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7736
	"/ fetch scaled brightness values outside of loop into a table;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7737
	"/ use table-value in loop
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7738
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7739
	greyValues := self greyMapForRange:(greyLevels).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7740
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7741
	greyPixels := greyValues collect:[:v | v isNil ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7742
						   0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7743
					       ] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7744
						   v truncated]].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7745
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7746
	greyPixels := ByteArray withAll:greyPixels.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7747
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7748
	greyErrors := greyValues collect:[:v | v isNil ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7749
						   0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7750
					       ] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7751
						   ((v - v truncated) * 1024) truncated
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7752
					       ]].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7753
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7754
	0 to:(h-1) do:[:y |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7755
	    nextDst := dstIndex + bytesPerOutRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7756
	    byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7757
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7758
	    t := errorArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7759
	    errorArray := nextErrorArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7760
	    nextErrorArray := t.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7761
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7762
	    nextErrorArray atAllPut:0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7763
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7764
	    self valuesAtY:y from:0 to:(w-1) do:[:x :value |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7765
		|e     "{ Class: SmallInteger }"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7766
		 pixel "{ Class: SmallInteger }"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7767
		 error "{ Class: SmallInteger }"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7768
		 e16   "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7769
		 xE    "{ Class: SmallInteger }"
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7770
		 xN    "{ Class: SmallInteger }" |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7771
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7772
		pixel := greyPixels at:(value + 1).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7773
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7774
		"/ adjust error
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7775
		xE := x + 2.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7776
		error := (greyErrors at:(value + 1)) + (errorArray at:xE).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7777
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7778
		byte := byte bitShift:depth.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7779
		error > 512 "0.5" ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7780
		    pixel := pixel + 1.
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7781
		    e := error - 1024 "1.0"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7782
		] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7783
		    e := error
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7784
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7785
		byte := byte bitOr:pixel.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7786
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7787
		e ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7788
		    e16 := e // 16.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7789
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7790
		    eR  := e16 * 7.              "/ 7/16 to right
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7791
		    eRB := e16 * 1.              "/ 1/16 to right below
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7792
		    eB  := e16 * 5.              "/ 5/16 to below
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7793
		    eLB := e - eR - eRB - eB.  "/ 3/16 to left below
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7794
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7795
		    xN := xE + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7796
		    eR ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7797
			errorArray     at:xN put:(errorArray at:xN) + eR.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7798
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7799
		    eRB ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7800
			nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7801
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7802
		    eB ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7803
			nextErrorArray at:xE put:(nextErrorArray at:xE) + eB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7804
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7805
		    eLB ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7806
			xN := xE - 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7807
			nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7808
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7809
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7810
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7811
		bitCnt := bitCnt - depth.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7812
		bitCnt == 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7813
		    outBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7814
		    dstIndex := dstIndex + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7815
		    byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7816
		    bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7817
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7818
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7819
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7820
	    bitCnt ~~ 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7821
		byte := byte bitShift:bitCnt.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7822
		outBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7823
		bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7824
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7825
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7826
	    dstIndex := nextDst.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7827
	].
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7828
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7829
	0 to:(h-1) do:[:y |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7830
	    nextDst := dstIndex + bytesPerOutRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7831
	    byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7832
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7833
	    t := errorArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7834
	    errorArray := nextErrorArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7835
	    nextErrorArray := t.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7836
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7837
	    nextErrorArray atAllPut:0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7838
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7839
	    self colorsAtY:y from:0 to:(w-1) do:[:x :clr |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7840
		|e     "{ Class: SmallInteger }"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7841
		 pixel "{ Class: SmallInteger }"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7842
		 error "{ Class: SmallInteger }"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7843
		 e16   "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7844
		 xE    "{ Class: SmallInteger }"
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7845
		 xN    "{ Class: SmallInteger }" |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7846
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7847
		grey := (clr brightness * greyLevels).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7848
		pixel := grey truncated.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7849
		error := ((grey - pixel) * 1024) truncated.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7850
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7851
		"/ adjust error
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7852
		xE := x + 2.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7853
		error := error + (errorArray at:xE).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7854
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7855
		byte := byte bitShift:depth.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7856
		error > 512 "0.5" ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7857
		    pixel := pixel + 1.
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7858
		    e := error - 1024 "1.0"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7859
		] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7860
		    e := error
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7861
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7862
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7863
		byte := byte bitOr:pixel.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7864
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7865
		e ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7866
		    e16 := e // 16.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7867
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7868
		    eR  := e16 * 7.              "/ 7/16 to right
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7869
		    eRB := e16 * 1.              "/ 1/16 to right below
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7870
		    eB  := e16 * 5.              "/ 5/16 to below
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7871
		    eLB := e - eR - eRB - eB.  "/ 3/16 to left below
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7872
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7873
		    xN := xE + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7874
		    eR ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7875
			errorArray     at:xN put:(errorArray at:xN) + eR.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7876
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7877
		    eRB ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7878
			nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7879
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7880
		    eB ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7881
			nextErrorArray at:xE put:(nextErrorArray at:xE) + eB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7882
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7883
		    eLB ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7884
			xN := xE - 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7885
			nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7886
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7887
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7888
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7889
		bitCnt := bitCnt - depth.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7890
		bitCnt == 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7891
		    outBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7892
		    dstIndex := dstIndex + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7893
		    byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7894
		    bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7895
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7896
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7897
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7898
	    bitCnt ~~ 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7899
		byte := byte bitShift:bitCnt.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7900
		outBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7901
		bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7902
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7903
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7904
	    dstIndex := nextDst.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7905
	].
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7906
    ].
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7907
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7908
    ^ outBits
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7909
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7910
    "Created: 10.6.1996 / 13:28:22 / cg"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7911
    "Modified: 11.6.1996 / 00:13:38 / cg"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7912
!
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7913
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7914
floydSteinbergDitheredMonochromeBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7915
    "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
  7916
     Works for any source depths / photometric,
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7917
     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
  7918
     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
  7919
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7920
    |dstIndex        "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7921
     nextDst         "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7922
     bytesPerMonoRow "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7923
     monoBits greyValues
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7924
     errorArray
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7925
     nextErrorArray
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7926
     e eD t
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7927
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7928
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7929
     bitCnt          "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7930
     byte            "{Class: SmallInteger }"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7931
     grey
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7932
     eR eRB eB eLB |
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7933
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7934
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7935
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7936
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7937
    bytesPerMonoRow := (w + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7938
    monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7939
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7940
    errorArray := Array new:w+2.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7941
    nextErrorArray := Array new:w+2.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7942
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7943
    nextErrorArray atAllPut:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7944
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7945
    dstIndex := 1.
828
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7946
    bitCnt := 8.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7947
    byte := 0.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7948
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7949
    self depth <= 12 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7950
	"/ fetch scaled brightness values outside of loop into a table;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7951
	"/ use table-value in loop
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7952
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7953
	greyValues := self greyMapForRange:(255 * 1024).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7954
	greyValues := greyValues collect:[:v | v rounded].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7955
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7956
	0 to:(h-1) do:[:y |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7957
	    nextDst := dstIndex + bytesPerMonoRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7958
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7959
	    t := errorArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7960
	    errorArray := nextErrorArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7961
	    nextErrorArray := t.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7962
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7963
	    nextErrorArray atAllPut:0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7964
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7965
	    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
  7966
%{
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7967
		int __grey, __e;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7968
		int __byte = __intVal(byte);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7969
		OBJ *__errorArray = __ArrayInstPtr(errorArray)->a_element;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7970
		OBJ *__nextErrorArray = __ArrayInstPtr(nextErrorArray)->a_element;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7971
		int __x = __intVal(x);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7972
		int __eR, __eB, __eRB, __eLB, __eI;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7973
		int __bitCnt = __intVal(bitCnt);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7974
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7975
		__grey = __intVal(__ArrayInstPtr(greyValues)->a_element[__intVal(pixel)]);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7976
		__grey += __intVal(__errorArray[__x+1]);
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7977
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7978
		__byte <<= 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7979
		if (__grey > 127*1024) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7980
		    __e = __grey - (255*1024);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7981
		    __byte |= 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7982
		} else {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7983
		    __e = __grey;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7984
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7985
		if (__e) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7986
		    __eI = __e >> 4;
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7987
		    __eR  = __eI * 7;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7988
		    __eRB = __eI * 1;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7989
		    __eB  = __eI * 5;
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7990
		    __eLB = __e - __eR - __eRB - __eB;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7991
		    __errorArray[__x+2] = __MKSMALLINT(__intVal(__errorArray[__x+2]) + __eR);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7992
		    __nextErrorArray[__x+2] = __MKSMALLINT(__intVal(__nextErrorArray[__x+2]) + __eRB);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7993
		    __nextErrorArray[__x+1] = __MKSMALLINT(__intVal(__nextErrorArray[__x+1]) + __eB);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7994
		    __nextErrorArray[__x  ] = __MKSMALLINT(__intVal(__nextErrorArray[__x  ]) + __eLB);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7995
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7996
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7997
		__bitCnt--;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7998
		if (__bitCnt == 0) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7999
		    int __dstIndex = __intVal(dstIndex);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8000
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8001
		    __ByteArrayInstPtr(monoBits)->ba_element[__dstIndex-1] = __byte;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8002
		    dstIndex = __MKSMALLINT(__dstIndex + 1);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8003
		    __byte = 0;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8004
		    __bitCnt = 8;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8005
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8006
		byte = __MKSMALLINT(__byte);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8007
		bitCnt = __MKSMALLINT(__bitCnt);
828
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8008
%}.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8009
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8010
"/                |eI "{ Class: SmallInteger }"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8011
"/                 xE "{ Class: SmallInteger }"
829
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  8012
"/                 xN "{ Class: SmallInteger }" |
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  8013
"/
828
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8014
"/                "/ get the colors grey value [0 .. 1]
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8015
"/                grey := greyValues at:(pixel + 1).
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8016
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8017
"/                "/ adjust error
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8018
"/                xE := x + 2.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8019
"/                grey := (grey + (errorArray at:xE)).
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8020
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8021
"/                byte := byte bitShift:1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8022
"/                grey > (127*1024) ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8023
"/                    byte := byte bitOr:1.      "/ white
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8024
"/                    e := grey - (255*1024)
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8025
"/                ] ifFalse:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8026
"/                    e := grey                  "/ black
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8027
"/                ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8028
"/                e ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8029
"/                    eD := e.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8030
"/                    eI := e // 16.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8031
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8032
"/                    eR  := eI * 7.              "/ 7/16 to right
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8033
"/                    eRB := eI * 1.              "/ 1/16 to right below
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8034
"/                    eB  := eI * 5.              "/ 5/16 to below
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8035
"/                    eLB := eD - eR - eRB - eB.  "/ 3/16 to left below
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8036
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8037
"/                    xN := xE + 1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8038
"/                    eR ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8039
"/                        errorArray     at:xN put:(errorArray at:xN) + eR.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8040
"/                    ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8041
"/                    eRB ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8042
"/                        nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8043
"/                    ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8044
"/                    eB ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8045
"/                        nextErrorArray at:xE put:(nextErrorArray at:xE) + eB.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8046
"/                    ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8047
"/                    eLB ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8048
"/                        xN := xE - 1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8049
"/                        nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8050
"/                    ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8051
"/                ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8052
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8053
"/                bitCnt := bitCnt - 1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8054
"/                bitCnt == 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8055
"/                    monoBits at:dstIndex put:byte.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8056
"/                    dstIndex := dstIndex + 1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8057
"/                    byte := 0.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8058
"/                    bitCnt := 8.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8059
"/                ].
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8060
		  0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8061
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8062
	    bitCnt ~~ 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8063
		byte := byte bitShift:bitCnt.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8064
		monoBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8065
		bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8066
		byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8067
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8068
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8069
	    dstIndex := nextDst.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8070
	].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8071
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8072
	'Image [info]: slow floydSteinberg dither ..' infoPrintCR.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8073
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8074
	0 to:(h-1) do:[:y |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8075
	    nextDst := dstIndex + bytesPerMonoRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8076
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8077
	    t := errorArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8078
	    errorArray := nextErrorArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8079
	    nextErrorArray := t.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8080
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8081
	    nextErrorArray atAllPut:0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8082
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8083
	    self colorsAtY:y from:0 to:(w-1) do:[:x :clr |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8084
		|eI "{ Class: SmallInteger }"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8085
		 xE "{ Class: SmallInteger }"
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8086
		 xN "{ Class: SmallInteger }" |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8087
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8088
		"/ get the colors grey value [0 .. 1]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8089
		grey := (clr brightness * 255).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8090
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8091
		"/ adjust error
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8092
		xE := x + 2.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8093
		grey := (grey + (errorArray at:xE)) rounded.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8094
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8095
		byte := byte bitShift:1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8096
		grey > 127 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8097
		    byte := byte bitOr:1.      "/ white
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8098
		    e := grey - 255
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8099
		] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8100
		    e := grey                  "/ black
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8101
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8102
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8103
		e ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8104
		    eD := e.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8105
		    eI := e // 16.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8106
		    eR  := eI * 7.              "/ 7/16 to right
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8107
		    eRB := eI * 1.              "/ 1/16 to right below
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8108
		    eB  := eI * 5.              "/ 5/16 to below
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8109
		    eLB := eD - eR - eRB - eB.  "/ 3/16 to left below
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8110
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8111
		    xN := xE + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8112
		    eR ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8113
			errorArray     at:xN put:(errorArray at:xN) + eR.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8114
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8115
		    eRB ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8116
			nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8117
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8118
		    eB ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8119
			nextErrorArray at:xE put:(nextErrorArray at:xE) + eB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8120
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8121
		    eLB ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8122
			xN := xE - 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8123
			nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8124
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8125
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8126
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8127
		bitCnt := bitCnt - 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8128
		bitCnt == 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8129
		    monoBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8130
		    dstIndex := dstIndex + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8131
		    byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8132
		    bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8133
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8134
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8135
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8136
	    bitCnt ~~ 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8137
		byte := byte bitShift:bitCnt.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8138
		monoBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8139
		bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8140
		byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8141
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8142
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8143
	    dstIndex := nextDst.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8144
	].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8145
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8146
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8147
    ^ monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8148
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8149
    "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
  8150
    "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
  8151
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8152
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8153
nearestPaintDepth8BitsColors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8154
    "return a nearest paint bitmap from the receiver picture,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8155
     which must be a depth-8 image.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8156
     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
  8157
     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
  8158
     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
  8159
     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
  8160
     Color class."
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8161
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8162
    |pseudoBits
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8163
     fixR    "{Class: SmallInteger }"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8164
     fixG    "{Class: SmallInteger }"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8165
     fixB    "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8166
     fixGfixB
884
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  8167
     r       "{Class: SmallInteger }"
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  8168
     g       "{Class: SmallInteger }"
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  8169
     b       "{Class: SmallInteger }"
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  8170
     idx     "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8171
     idMap lastColor
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8172
     clr|
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8173
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8174
    self depth ~~ 8 ifTrue:[^ nil].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8175
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8176
    photometric == #palette ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8177
	lastColor := colorMap size - 1
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8178
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8179
	lastColor := 255.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8180
    ].
884
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  8181
    idMap := ByteArray uninitializedNew:256.
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  8182
3915
dd2dae91c068 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3914
diff changeset
  8183
    (nRed isNil or:[nGreen isNil or:[nBlue isNil]]) ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8184
	0 to:lastColor do:[:pix |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8185
	    |clr repClr|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8186
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8187
	    clr := self colorFromValue:pix.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8188
	    repClr := clr nearestIn:fixColors.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8189
	    idMap at:(pix+1) put:(fixColors identityIndexOf:repClr)-1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8190
	].
3914
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  8191
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8192
	fixR := nRed.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8193
	fixR == 0 ifTrue:[ ^ nil].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8194
	fixG := nGreen.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8195
	fixG == 0 ifTrue:[ ^ nil].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8196
	fixB := nBlue.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8197
	fixB == 0 ifTrue:[ ^ nil].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8198
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8199
	"/ simple check
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8200
	(fixR * fixG * fixB) ~~ fixColors size ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8201
	    self error:'invalid color array passed'.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8202
	    ^ nil
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8203
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8204
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8205
	"/
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8206
	"/ collect colorIds
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8207
	"/
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8208
	fixGfixB := fixG * fixB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8209
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8210
	0 to:lastColor do:[:pix |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8211
	    clr := self colorFromValue:pix.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8212
	    r := clr redByte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8213
	    g := clr greenByte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8214
	    b := clr blueByte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8215
	    idx := ((r * (fixR-1) + 128) // 255) * fixGfixB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8216
	    idx := idx + (((g * (fixG-1) + 128) // 255) * fixB).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8217
	    idx := idx + ((b * (fixB-1) + 128) // 255).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8218
	    idMap at:(pix+1) put:(fixColors at:(idx+1)) colorId.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8219
	].
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8220
    ].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8221
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8222
    pseudoBits := ByteArray uninitializedNew:(width * height).
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8223
884
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  8224
    "/ translate
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  8225
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  8226
    self bits
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8227
	expandPixels:8         "xlate only"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8228
	width:width height:height
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8229
	into:pseudoBits
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8230
	mapping:idMap.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8231
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8232
    ^ pseudoBits
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8233
884
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  8234
    "Modified: 18.6.1996 / 09:18:09 / cg"
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8235
!
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8236
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8237
nfloydSteinbergDitheredDepth8BitsColors:colors
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8238
    "return a floyd-steinberg dithered bitmap from the receiver picture,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8239
     which must be a depth-8 image.
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8240
     This method expects an array of colors to be used for dithering
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8241
     (which need not be a colorCubes colors)."
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8242
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8243
    |pseudoBits
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8244
     rgbBytes
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8245
     ditherRGBBytes ditherColors
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8246
     w       "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8247
     h       "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8248
     index   "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8249
     numR    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8250
     numG    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8251
     numB    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8252
     bitsR    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8253
     bitsG    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8254
     bitsB    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8255
     maxBits  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8256
     maskR    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8257
     maskG    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8258
     maskB    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8259
     shR      "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8260
     shG      "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8261
     shB      "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8262
     ditherIds failed map lastColor colorsByDistance qScramble
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8263
     clrLookup lookupPos cube nCube
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8264
     dR  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8265
     dG  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8266
     dB  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8267
     iR    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8268
     iRG   "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8269
     iRGB  "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8270
     clr
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8271
     rI  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8272
     gI  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8273
     bI  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8274
     maxIDX  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8275
     subCubeColorCollection
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8276
     error
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8277
     dl "{Class: SmallInteger }"|
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8278
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8279
    self depth ~~ 8 ifTrue:[^ nil].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8280
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8281
    "/
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8282
    "/ collect color components as integer values (for integer arithmetic)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8283
    "/
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8284
    rgbBytes := ByteArray uninitializedNew:256 * 3.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8285
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8286
    photometric == #palette ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8287
	lastColor := colorMap size - 1
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8288
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8289
	lastColor := 255.
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8290
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8291
    index := 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8292
    0 to:lastColor do:[:pix |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8293
	clr := self colorFromValue:pix.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8294
	rgbBytes at:index put:(clr redByte).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8295
	rgbBytes at:index+1 put:(clr greenByte).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8296
	rgbBytes at:index+2 put:(clr blueByte).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8297
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8298
	index := index + 3.
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8299
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8300
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8301
    "/ collect valid ditherColors ...
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8302
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8303
    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
  8304
    ditherColors := ditherColors select:[:clr | clr colorId notNil].
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8305
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8306
    "/ collect ditherColor components
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8307
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8308
    lastColor := ditherColors size.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8309
    ditherIds := ByteArray uninitializedNew:lastColor.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8310
    ditherRGBBytes := ByteArray uninitializedNew:(lastColor * 3).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8311
    index := 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8312
    1 to:lastColor do:[:pix |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8313
	clr := ditherColors at:pix.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8314
	ditherRGBBytes at:index put:(clr redByte).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8315
	ditherRGBBytes at:index+1 put:(clr greenByte).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8316
	ditherRGBBytes at:index+2 put:(clr blueByte).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8317
	ditherIds at:pix put:clr colorId.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8318
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8319
	index := index + 3.
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8320
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8321
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8322
    "/ place the ditherColor positions into a color cube
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8323
    bitsR := 5.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8324
    bitsG := 6.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8325
    bitsB := 4.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8326
    maxBits := 6.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8327
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8328
"/    bitsR := 4.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8329
"/    bitsG := 4.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8330
"/    bitsB := 3.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8331
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8332
    numR := 1 bitShift:bitsR.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8333
    numG := 1 bitShift:bitsG.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8334
    numB := 1 bitShift:bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8335
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8336
    maskR := (numR-1) bitShift:(bitsG + bitsB).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8337
    maskG := (numG-1) bitShift:bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8338
    maskB := numB-1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8339
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8340
    shR := -16+bitsR+bitsG+bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8341
    shG := -16+bitsG+bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8342
    shB := -16+bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8343
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8344
    maxIDX := numR*numG*numB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8345
    cube := Array new:maxIDX.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8346
    1 to:lastColor do:[:clrIdx |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8347
	clr := ditherColors at:clrIdx.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8348
	rI := clr scaledRed. rI := (rI bitShift:shR) bitAnd:maskR.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8349
	gI := clr scaledGreen. gI := (gI bitShift:shG) bitAnd:maskG.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8350
	bI := clr scaledBlue. bI := (bI bitShift:shB) bitAnd:maskB.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8351
	index := rI + gI + bI + 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8352
	subCubeColorCollection := cube at:index.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8353
	subCubeColorCollection isNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8354
	    subCubeColorCollection := OrderedCollection new.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8355
	    cube at:index put:subCubeColorCollection.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8356
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8357
	subCubeColorCollection add:(clrIdx - 1).
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8358
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8359
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8360
    shR := 1 bitShift:(bitsG+bitsB).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8361
    shG := 1 bitShift:(bitsB).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8362
    shB := 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8363
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8364
    1 to:maxIDX do:[:i |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8365
	subCubeColorCollection := cube at:i.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8366
	subCubeColorCollection notNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8367
	    cube at:i put:(subCubeColorCollection asByteArray)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8368
	]
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8369
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8370
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8371
"/    nCube := cube copy.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8372
"/
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8373
"/    cube keysAndValuesDo:[:i :indices |
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8374
"/        indices notNil ifTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8375
"/            nCube at:i put:(indices asByteArray)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8376
"/        ] ifFalse:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8377
"/            "/ find nearest color
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8378
"/
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8379
"/            dl := 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8380
"/            [dl < maxBits] whileTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8381
"/                dR := dl negated.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8382
"/                [dR <= dl] whileTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8383
"/                    iR := i + (dR * shR).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8384
"/                    (iR > 0 and:[iR < maxIDX]) ifTrue:[
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8385
"/                        dG := dl negated.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8386
"/                        [dG < dl] whileTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8387
"/                            iRG := iR + (dG * shG).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8388
"/                            (iRG > 0 and:[iRG < maxIDX]) ifTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8389
"/                                dB := dl negated.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8390
"/                                [dB < dl] whileTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8391
"/                                    iRGB := iRG + dB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8392
"/                                    (iRG > 0 and:[iRG < maxIDX]) ifTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8393
"/                                        (cube at:iRGB) notNil ifTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8394
"/                                            nCube at:i put:(cube at:iRGB).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8395
"/                                            dB := dG := dR := dl := 999.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8396
"/                                        ]
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8397
"/                                    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8398
"/                                    dB := dB + 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8399
"/                                ]
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8400
"/                            ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8401
"/                            dG := dG + 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8402
"/                        ]
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8403
"/                    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8404
"/                    dR := dR + 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8405
"/                ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8406
"/                dl := dl + 1.
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
"/    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8410
"/self halt.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8411
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8412
    "/ now, cube contains collections of colors which are
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8413
    "/ positioned in a subCube; quickly accessed by a lookup
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8414
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8415
    pseudoBits := ByteArray uninitializedNew:(width * height).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8416
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8417
    w := width.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8418
    h := height.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8419
    error := ByteArray new:(w+2)*3*2.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8420
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8421
%{
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8422
#define BITSR   5
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8423
#define BITSG   6
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8424
#define BITSB   4
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8425
#define MAXBITS 6
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8426
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8427
#define xBITSR   4
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8428
#define xBITSG   4
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8429
#define xBITSB   3
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8430
#define xMAXBITS 4
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8431
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8432
#define NR      32 /* (1<<BITSR) */
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8433
#define NG      64 /* (1<<BITSG) */
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8434
#define NB      16 /* (1<<BITSB) */
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8435
#define MAXRGB  64 /* (1<<MAXBITS) */
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8436
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8437
#define SHR     (BITSG+BITSB)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8438
#define SHG     BITSB
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
#define REMEMBER_SEARCH
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8441
#define xNO_FLOYD_STEINBERG
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8442
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8443
    int __x, __y;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8444
    int __eR, __eG, __eB;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8445
    unsigned char *srcP, *dstP;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8446
    unsigned char *rgbP;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8447
    unsigned char *idP;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8448
    short *errP, *eP;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8449
    int __fR, __fG, __fB;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8450
    int idx;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8451
    int __w = __intVal(w);
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8452
    int __h = __intVal(h);
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8453
    int __nColors = __intVal(lastColor);
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8454
    int __wR = -1, __wG, __wB;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8455
    OBJ *__cube;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8456
    int cubeIndex, cubeIndex2;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8457
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8458
    if (__isByteArrayLike(__INST(bytes))
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8459
     && __isByteArray(pseudoBits)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8460
     && __isByteArray(rgbBytes)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8461
     && __isByteArray(ditherRGBBytes)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8462
     && __isByteArray(ditherIds)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8463
     && __isByteArray(error)) {
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8464
	failed = false;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8465
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8466
	srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8467
	dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8468
	rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8469
	idP = __ByteArrayInstPtr(ditherIds)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8470
	errP = (short *) __ByteArrayInstPtr(error)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8471
	__cube = __ArrayInstPtr(cube)->a_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8472
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8473
	eP = errP;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8474
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8475
	for (__y=__h; __y>0; __y--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8476
	    eP = &(errP[3]);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8477
	    __eR = eP[0];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8478
	    __eG = eP[1];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8479
	    __eB = eP[2];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8480
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8481
	    for (__x=__w; __x>0; __x--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8482
		int __want;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8483
		int pix;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8484
		int __wantR, __wantG, __wantB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8485
		int idx;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8486
		int tR, tG, tB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8487
		int nR, nG, nB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8488
		int __dR, __dG, __dB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8489
		int minDelta, bestIdx;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8490
		int __iR, __iG, __iB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8491
		int cR, cG, cB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8492
		int delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8493
		OBJ subCubeColors;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8494
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8495
		pix = *srcP++;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8496
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8497
		/*
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8498
		 * wR, wG and wB is the wanted r/g/b value;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8499
		 */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8500
		idx = pix+pix+pix;  /* pix * 3 */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8501
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8502
		__wR = __wantR = rgbP[idx] + __eR;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8503
		__wG = __wantG = rgbP[idx+1] + __eG;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8504
		__wB = __wantB = rgbP[idx+2] + __eB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8505
		if(__wR > 255) __wR = 255;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8506
		else if (__wR < 0) __wR = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8507
		if(__wG > 255) __wG = 255;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8508
		else if (__wG < 0) __wG = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8509
		if(__wB > 255) __wB = 255;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8510
		else if (__wB < 0) __wB = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8511
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8512
		__iR = __wR >> (8-BITSR);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8513
		__iG = __wG >> (8-BITSG);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8514
		__iB = __wB >> (8-BITSB);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8515
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8516
		cubeIndex = (__iR<<SHR) + (__iG<<SHG) + __iB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8517
		subCubeColors = __cube[cubeIndex];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8518
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8519
		if (subCubeColors == nil) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8520
		    /* search around in spirals, for the first match */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8521
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8522
		    delta = 1;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8523
		    while (delta < MAXRGB) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8524
			/* check plane above */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8525
			cR = __iR + delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8526
			if ((unsigned)cR < NR) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8527
			    for (cG=__iG-delta; cG<=__iG+delta; cG++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8528
				if ((unsigned)cG < NG) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8529
				    for (cB=__iB-delta; cB<=__iB+delta; cB++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8530
					if ((unsigned)cB < NB) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8531
					    cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8532
					    subCubeColors = __cube[cubeIndex2];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8533
					    if (__isNonNilObject(subCubeColors)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8534
						goto found;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8535
					    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8536
					}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8537
				    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8538
				}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8539
			    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8540
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8541
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8542
			/* check plane below */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8543
			cR = __iR - delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8544
			if ((unsigned)cR < NR) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8545
			    for (cG=__iG-delta; cG<=__iG+delta; cG++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8546
				if ((unsigned)cG < NG) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8547
				    for (cB=__iB-delta; cB<=__iB+delta; cB++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8548
					if ((unsigned)cB < NB) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8549
					    cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8550
					    subCubeColors = __cube[cubeIndex2];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8551
					    if (__isNonNilObject(subCubeColors)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8552
						goto found;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8553
					    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8554
					}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8555
				    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8556
				}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8557
			    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8558
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8559
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8560
			/* check plane to the right */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8561
			cG = __iG + delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8562
			if ((unsigned)cG < NG) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8563
			    for (cR=__iR-delta+1; cR<=__iR+delta-1; cR++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8564
				if ((unsigned)cR < NR) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8565
				    for (cB=__iB-delta; cB<=__iB+delta; cB++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8566
					if ((unsigned)cB < NB) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8567
					    cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8568
					    subCubeColors = __cube[cubeIndex2];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8569
					    if (__isNonNilObject(subCubeColors)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8570
						goto found;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8571
					    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8572
					}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8573
				    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8574
				}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8575
			    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8576
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8577
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8578
			/* check plane to the left */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8579
			cG = __iG - delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8580
			if ((unsigned)cG < NG) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8581
			    for (cR=__iR-delta+1; cR<=__iR+delta-1; cR++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8582
				if ((unsigned)cR < NR) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8583
				    for (cB=__iB-delta; cB<=__iB+delta; cB++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8584
					if ((unsigned)cB < NB) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8585
					    cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8586
					    subCubeColors = __cube[cubeIndex2];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8587
					    if (__isNonNilObject(subCubeColors)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8588
						goto found;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8589
					    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8590
					}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8591
				    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8592
				}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8593
			    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8594
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8595
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8596
			/* check plane at back */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8597
			cB = __iB + delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8598
			if ((unsigned)cB < NB) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8599
			    for (cR=__iR-delta+1; cR<=(__iR+delta-1); cR++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8600
				if ((unsigned)cR < NR) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8601
				    for (cG=__iG-delta+1; cG<=(__iG+delta-1); cG++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8602
					if ((unsigned)cG < NG) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8603
					    cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8604
					    subCubeColors = __cube[cubeIndex2];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8605
					    if (__isNonNilObject(subCubeColors)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8606
						goto found;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8607
					    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8608
					}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8609
				    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8610
				}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8611
			    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8612
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8613
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8614
			/* check plane at front */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8615
			cB = __iB - delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8616
			if ((unsigned)cB < NB) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8617
			    for (cR=__iR-delta+1; cR<=(__iR+delta-1); cR++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8618
				if ((unsigned)cR < NR) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8619
				    for (cG=__iG-delta+1; cG<=(__iG+delta-1); cG++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8620
					if ((unsigned)cG < NG) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8621
					    cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8622
					    subCubeColors = __cube[cubeIndex2];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8623
					    if (__isNonNilObject(subCubeColors)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8624
						goto found;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8625
					    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8626
					}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8627
				    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8628
				}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8629
			    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8630
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8631
			delta = delta + 1;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8632
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8633
		    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8634
		    /* cannot happen - will lead to a segmentation violation ... */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8635
		    subCubeColors = nil;
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8636
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8637
    found:
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8638
		    __iR = cR;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8639
		    __iG = cG;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8640
		    __iB = cB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8641
		    bestIdx = __ByteArrayInstPtr(subCubeColors)->ba_element[0];
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8642
#ifdef REMEMBER_SEARCH
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8643
		    __cube[cubeIndex] = __MKSMALLINT(bestIdx);
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8644
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8645
		} else {
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8646
#ifdef REMEMBER_SEARCH
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8647
		    if (__isSmallInteger(subCubeColors)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8648
			bestIdx = __intVal(subCubeColors);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8649
		    } else
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8650
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8651
		    {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8652
			bestIdx = __ByteArrayInstPtr(subCubeColors)->ba_element[0];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8653
		    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8654
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8655
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8656
		/*
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8657
		 * ok, now, we have found a collection of nearby
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8658
		 * colors in subCubeColors.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8659
		 *
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8660
		 * since the error is at most 1/16 (i.e. roughly 6%),
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8661
		 * dont care for searching the best - simply take the
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8662
		 * first color found there.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8663
		 * (statistic reduces the error to even a smaller value).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8664
		 * There is no real problem due to that error, since
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8665
		 * it will be diffused anyway ...
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8666
		 */
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8667
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8668
#ifndef NO_FLOYD_STEINBERG
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8669
		{
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8670
		    unsigned char *dp;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8671
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8672
		    /*
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8673
		     * fetch that colors r/g/b components
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8674
		     */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8675
		    dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8676
		    dp += bestIdx * 3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8677
		    __dR = dp[0];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8678
		    __dG = dp[1];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8679
		    __dB = dp[2];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8680
		}
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8681
#endif
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8682
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8683
/*
4725
c8896df7bd3f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4717
diff changeset
  8684
console_fprintf(stderr, "want: %d/%d/%d (%d/%d/%d) got: %d/%d/%d\n",
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8685
		__wantR, __wantG, __wantB,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8686
		__wR, __wG, __wB,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8687
		__dR, __dG, __dB);
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8688
*/
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8689
		/*
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8690
		 * store the corresponding dither colors colorId
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8691
		 */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8692
		*dstP++ = idP[bestIdx];
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8693
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8694
#ifndef NO_FLOYD_STEINBERG
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8695
		/*
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8696
		 * the new error & distribute the error
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8697
		 */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8698
		__eR = __wantR - __dR;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8699
		if (__eR) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8700
		    tR = __eR >> 4;  /* 16th of error */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8701
		    nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8702
		    eP[0] = tR*5;         /* 5/16th for (x / y+1) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8703
		    eP[-3] = tR*3;        /* 3/16th for (x-1 / y+1) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8704
		    eP[3] = __eR - (tR*15);  /* 1/16th for (x+1 / y+1) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8705
		    __eR = nR;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8706
		} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8707
		    __eR = eP[3];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8708
		    eP[0] = eP[-3] = eP[3] = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8709
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8710
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8711
		__eG = __wantG - __dG;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8712
		if (__eG) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8713
		    tG = __eG >> 4;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8714
		    nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8715
		    eP[1] = tG*5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8716
		    eP[-2] = tG*3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8717
		    eP[4] = __eG - (tG*15);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8718
		    __eG = nG;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8719
		} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8720
		    __eG = eP[4];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8721
		    eP[1] = eP[-2] = eP[4] = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8722
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8723
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8724
		__eB = __wantB - __dB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8725
		if (__eB) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8726
		    tB = __eB >> 4;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8727
		    nB = eP[5] + (tB * 7);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8728
		    eP[2] = tB*5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8729
		    eP[-1] = tB*3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8730
		    eP[5] = __eB - (tB*15);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8731
		    __eB = nB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8732
		} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8733
		    __eB = eP[5];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8734
		    eP[2] = eP[-1] = eP[5] = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8735
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8736
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8737
		eP += 3;
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8738
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8739
	    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8740
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8741
	    /*
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8742
	     * allow for an interrupt after every row.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8743
	     * but care to refetch C variables
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8744
	     */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8745
	    if (InterruptPending) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8746
		int d_srcP = srcP - __ByteArrayInstPtr(__INST(bytes))->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8747
		int d_dstP = dstP - __ByteArrayInstPtr(pseudoBits)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8748
		int d_errP = errP - (short *) __ByteArrayInstPtr(error)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8749
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8750
		__interrupt__();
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8751
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8752
		srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element + d_srcP;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8753
		dstP = __ByteArrayInstPtr(pseudoBits)->ba_element + d_dstP;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8754
		rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8755
		idP = __ByteArrayInstPtr(ditherIds)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8756
		errP = (short *) __ByteArrayInstPtr(error)->ba_element + d_errP;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8757
		__cube = __ArrayInstPtr(cube)->a_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8758
	    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8759
	}
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8760
    }
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8761
%}.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8762
    failed ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8763
	self primitiveFailed.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8764
	^ nil
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8765
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8766
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8767
    ^ pseudoBits
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8768
!
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8769
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8770
orderedDitheredGrayBitsDepth:depth
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8771
    "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
  8772
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8773
    ^ self
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8774
	orderedDitheredGrayBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8775
	ditherWidth:8
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8776
	depth:depth.
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8777
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8778
    "Created: 24.6.1997 / 22:20:12 / cg"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8779
!
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8780
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8781
orderedDitheredGrayBitsWithDitherMatrix:ditherMatrix ditherWidth:dW depth:depth
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8782
    "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
  8783
     with a constant ditherMatrix, this can be used for thresholding.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8784
     Works for any source depths / photometric,
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8785
     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
  8786
     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
  8787
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8788
    |dH nDither
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8789
     greyLevels greyValues greyPixels greyErrors
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8790
     dstIndex        "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8791
     nextDst
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8792
     bytesPerOutRow  "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8793
     pixelsPerByte   "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8794
     outBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8795
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8796
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8797
     bitCnt          "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8798
     byte            "{Class: SmallInteger }" |
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8799
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8800
    depth > 8 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8801
	'IMAGE: unimplemented orderedDither conversion' errorPrintCR.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8802
	^ nil
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8803
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8804
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8805
    nDither := ditherMatrix size.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8806
    dH := nDither / dW.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8807
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8808
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8809
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8810
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8811
    greyLevels := 1 bitShift:depth.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8812
    pixelsPerByte := 8 / depth.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8813
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8814
    bytesPerOutRow := (w * depth + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8815
    outBits := ByteArray uninitializedNew:(bytesPerOutRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8816
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8817
    dstIndex := 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8818
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8819
    self bitsPerPixel <= 12 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8820
	"/ fetch scaled brightness values outside of loop into a table;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8821
	"/ use table-value in loop
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8822
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8823
	greyValues := self greyMapForRange:(greyLevels-1).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8824
	greyPixels := greyValues collect:[:v | v isNil ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8825
						   0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8826
					       ] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8827
						   v truncated]].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8828
	greyPixels := ByteArray withAll:greyPixels.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8829
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8830
	greyErrors := greyValues collect:[:v | v isNil ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8831
						   0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8832
					       ] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8833
						   ((v - v truncated) * nDither) rounded
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8834
					       ]].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8835
	greyErrors := ByteArray withAll:greyErrors.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8836
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8837
	0 to:(h-1) do:[:y |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8838
	    nextDst := dstIndex + bytesPerOutRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8839
	    byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8840
	    bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8841
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8842
	    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
  8843
%{
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8844
		int __dW = __intVal(dW);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8845
		int __byte = __intVal(byte);
4745
778644e0c89b Can compile with MS Visual C++ 8 / 2005
Stefan Vogel <sv@exept.de>
parents: 4725
diff changeset
  8846
		/* Note: __value is reserved in Visual C++ 8 (2005) */
778644e0c89b Can compile with MS Visual C++ 8 / 2005
Stefan Vogel <sv@exept.de>
parents: 4725
diff changeset
  8847
		int __val = __intVal(value);
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8848
		int __dT;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8849
		int __dstIdx;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8850
		int __pixel, __grey;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8851
		int __bitCnt = __intVal(bitCnt);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8852
		unsigned char *__greyPixels = __ByteArrayInstPtr(greyPixels)->ba_element;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8853
		unsigned char *__greyErrors = __ByteArrayInstPtr(greyErrors)->ba_element;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8854
4745
778644e0c89b Can compile with MS Visual C++ 8 / 2005
Stefan Vogel <sv@exept.de>
parents: 4725
diff changeset
  8855
		__pixel = __greyPixels[__val];
778644e0c89b Can compile with MS Visual C++ 8 / 2005
Stefan Vogel <sv@exept.de>
parents: 4725
diff changeset
  8856
		__grey = __greyErrors[__val];
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8857
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8858
		__dT = __ByteArrayInstPtr(ditherMatrix)
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8859
			    ->ba_element[__intVal(x) % __dW
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8860
					 + (__intVal(y) % __intVal(dH)) * __dW];
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8861
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8862
		if (__grey > __dT) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8863
		    __pixel++;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8864
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8865
		__byte = (__byte << __intVal(depth)) | __pixel;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8866
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8867
		__bitCnt = __bitCnt - __intVal(depth);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8868
		if (__bitCnt == 0) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8869
		    __dstIdx = __intVal(dstIndex);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8870
		    __ByteArrayInstPtr(outBits)->ba_element[__dstIdx-1] = __byte;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8871
		    __dstIdx = __dstIdx + 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8872
		    dstIndex = __MKSMALLINT(__dstIdx);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8873
		    __byte = 0;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8874
		    __bitCnt = 8;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8875
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8876
		byte = __MKSMALLINT(__byte);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8877
		bitCnt = __MKSMALLINT(__bitCnt);
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8878
%}.
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8879
		0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8880
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8881
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8882
	    bitCnt ~~ 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8883
		byte := byte bitShift:bitCnt.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8884
		outBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8885
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8886
	    dstIndex := nextDst.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8887
	].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8888
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8889
	'Image [info]: slow ordered dither ..' infoPrintCR.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8890
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8891
	0 to:(h-1) do:[:y |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8892
	    nextDst := dstIndex + bytesPerOutRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8893
	    byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8894
	    bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8895
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8896
	    "/ this is the representaion independent (but slow)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8897
	    "/ inner loop - it extracts colors from the receiver
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8898
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8899
	    self colorsAtY:y from:0 to:(w-1) do:[:x :clr |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8900
		|dstClr grey dT pixel|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8901
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8902
		"/ get the colors grey value [0 .. 1]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8903
		grey := clr brightness.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8904
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8905
		"/ remap into [0 .. greyLevels-1]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8906
		grey := grey * (greyLevels-1).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8907
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8908
		"/ get threshold pixel [0 .. greyLevels-1]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8909
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8910
		pixel := grey truncated.
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8911
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8912
		"/ compute the error [0..1]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8913
		grey := grey - pixel.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8914
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8915
		"/ map into dither space [0 .. nDither]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8916
		grey := (grey * (nDither)) rounded.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8917
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8918
%{
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8919
		int __dW = __intVal(dW);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8920
		int __byte = __intVal(byte);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8921
		int __dT;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8922
		int __dstIdx;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8923
		int __pixel;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8924
		int __bitCnt = __intVal(bitCnt);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8925
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8926
		__dT = __ByteArrayInstPtr(ditherMatrix)
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8927
			    ->ba_element[__intVal(x) % __dW
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8928
					 + (__intVal(y) % __intVal(dH)) * __dW];
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8929
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8930
		__pixel = __intVal(pixel);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8931
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8932
		if (__intVal(grey) > __dT) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8933
		    __pixel++;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8934
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8935
		__byte = (__byte << __intVal(depth)) | __pixel;
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8936
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8937
		__bitCnt = __bitCnt - __intVal(depth);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8938
		if (__bitCnt == 0) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8939
		    __dstIdx = __intVal(dstIndex);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8940
		    __ByteArrayInstPtr(outBits)->ba_element[__dstIdx-1] = __byte;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8941
		    __dstIdx = __dstIdx + 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8942
		    dstIndex = __MKSMALLINT(__dstIdx);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8943
		    __byte = 0;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8944
		    __bitCnt = 8;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8945
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8946
		byte = __MKSMALLINT(__byte);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8947
		bitCnt = __MKSMALLINT(__bitCnt);
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8948
%}.
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8949
		0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8950
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8951
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8952
	    bitCnt ~~ 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8953
		byte := byte bitShift:bitCnt.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8954
		outBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8955
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8956
	    dstIndex := nextDst.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8957
	].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8958
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8959
    ^ outBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8960
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8961
831
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8962
orderedDitheredMonochromeBits
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8963
    "return the bitmap for a dithered monochrome bitmap from the image;
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8964
     using a default ditherMatrix."
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8965
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8966
    ^ self
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8967
	orderedDitheredMonochromeBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8968
	ditherWidth:8
831
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8969
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8970
    "Created: 11.6.1996 / 16:48:57 / cg"
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8971
!
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8972
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8973
orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8974
    "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
  8975
     with a constant ditherMatrix, this can be used for thresholding.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8976
     Works for any source depths / photometric,
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8977
     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
  8978
     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
  8979
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8980
    |dH nDither
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8981
     greyValues
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8982
     dstIndex        "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8983
     nextDst         "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8984
     bytesPerMonoRow "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8985
     monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8986
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8987
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8988
     bitCnt          "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8989
     byte            "{Class: SmallInteger }" |
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8990
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8991
    nDither := ditherMatrix size.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8992
    dH := nDither / dW.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8993
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8994
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8995
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8996
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8997
    bytesPerMonoRow := (w + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8998
    monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8999
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9000
    dstIndex := 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9001
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9002
    self bitsPerPixel <= 12 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9003
	"/ fetch scaled brightness values outside of loop into a table;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9004
	"/ use table-value in loop
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9005
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9006
	greyValues := self greyByteMapForRange:nDither.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9007
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9008
	0 to:(h-1) do:[:y |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9009
	    nextDst := dstIndex + bytesPerMonoRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9010
	    byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9011
	    bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9012
	    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
  9013
%{
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9014
		int __dW = __intVal(dW);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9015
		int __byte = __intVal(byte);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9016
		int __dT;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9017
		int __dstIdx;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9018
		int __bitCnt = __intVal(bitCnt);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9019
		int __grey;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9020
		unsigned char *__greyValues = __ByteArrayInstPtr(greyValues)->ba_element;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9021
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9022
		__grey = __greyValues[__intVal(value)];
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9023
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9024
		__dT = __ByteArrayInstPtr(ditherMatrix)
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9025
			    ->ba_element[__intVal(x) % __dW
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9026
					 + (__intVal(y) % __intVal(dH)) * __dW];
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9027
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9028
		__byte = __byte << 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9029
		if (__grey > __dT) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9030
		    __byte = __byte | 1;            /* white */
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9031
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9032
		__bitCnt = __bitCnt - 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9033
		if (__bitCnt == 0) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9034
		    __dstIdx = __intVal(dstIndex);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9035
		    __ByteArrayInstPtr(monoBits)->ba_element[__dstIdx-1] = __byte;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9036
		    __dstIdx = __dstIdx + 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9037
		    dstIndex = __MKSMALLINT(__dstIdx);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9038
		    __byte = 0;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9039
		    __bitCnt = 8;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9040
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9041
		byte = __MKSMALLINT(__byte);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9042
		bitCnt = __MKSMALLINT(__bitCnt);
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9043
%}.
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9044
		0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9045
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9046
	    bitCnt ~~ 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9047
		byte := byte bitShift:bitCnt.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9048
		monoBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9049
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9050
	    dstIndex := nextDst.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9051
	].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9052
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9053
	'Image [info]: slow ordered dither ..' infoPrintCR.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9054
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9055
	0 to:(h-1) do:[:y |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9056
	    nextDst := dstIndex + bytesPerMonoRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9057
	    byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9058
	    bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9059
	    self colorsAtY:y from:0 to:(w-1) do:[:x :clr |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9060
		|dstClr grey dT|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9061
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9062
		"/ get the colors grey value [0 .. 1]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9063
		grey := clr brightness.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9064
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9065
		"/ map into dither space [0 .. nDither]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9066
		grey := (grey * (nDither)) rounded.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9067
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9068
%{
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9069
		int __dW = __intVal(dW);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9070
		int __byte = __intVal(byte);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9071
		int __dT;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9072
		int __dstIdx;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9073
		int __bitCnt = __intVal(bitCnt);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9074
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9075
		__dT = __ByteArrayInstPtr(ditherMatrix)
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9076
			    ->ba_element[__intVal(x) % __dW
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9077
					 + (__intVal(y) % __intVal(dH)) * __dW];
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9078
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9079
		__byte = __byte << 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9080
		if (__intVal(grey) > __dT) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9081
		    __byte = __byte | 1;            /* white */
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9082
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9083
		__bitCnt = __bitCnt - 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9084
		if (__bitCnt == 0) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9085
		    __dstIdx = __intVal(dstIndex);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9086
		    __ByteArrayInstPtr(monoBits)->ba_element[__dstIdx-1] = __byte;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9087
		    __dstIdx = __dstIdx + 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9088
		    dstIndex = __MKSMALLINT(__dstIdx);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9089
		    __byte = 0;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9090
		    __bitCnt = 8;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9091
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9092
		byte = __MKSMALLINT(__byte);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9093
		bitCnt = __MKSMALLINT(__bitCnt);
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9094
%}.
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9095
		0
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9096
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9097
"/                dT := ditherMatrix at:(x \\ dW) + (y \\ dH * dW) + 1.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9098
"/
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9099
"/                byte := byte bitShift:1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9100
"/                grey < dT ifTrue:[
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9101
"/                    byte := byte bitOr:1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9102
"/                ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9103
"/                bitCnt := bitCnt - 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9104
"/                bitCnt == 0 ifTrue:[
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9105
"/                    monoBits at:dstIndex put:byte.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9106
"/                    dstIndex := dstIndex + 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9107
"/                    byte := 0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9108
"/                    bitCnt := 8.
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
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9111
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9112
	    bitCnt ~~ 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9113
		byte := byte bitShift:bitCnt.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9114
		monoBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9115
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9116
	    dstIndex := nextDst.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9117
	].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9118
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9119
    ^ monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9120
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9121
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9122
stevensonArceDitheredMonochromeBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9123
    "return the bitmap for a dithered monochrome bitmap from the image.
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9124
     Works for any source depths / photometric.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9125
     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
  9126
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  9127
    |dstIndex        "{Class: SmallInteger }"
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9128
     nextDst         "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9129
     bytesPerMonoRow "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9130
     monoBits greyValues
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9131
     errorArray
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9132
     errorArray1 errorArray2 errorArray3
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9133
     e t
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9134
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9135
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9136
     bitCnt          "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9137
     byte            "{Class: SmallInteger }"
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  9138
     grey
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  9139
     xE              "{Class: SmallInteger }" |
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9140
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9141
    self depth > 12 ifTrue:[
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9142
        ^ self floydSteinbergDitheredMonochromeBits
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9143
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9144
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9145
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9146
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9147
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9148
    bytesPerMonoRow := (w + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9149
    monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9150
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9151
    errorArray := Array new:(w+6).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9152
    errorArray1 := Array new:(w+6) withAll:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9153
    errorArray2 := Array new:(w+6) withAll:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9154
    errorArray3 := Array new:(w+6) withAll:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9155
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9156
    dstIndex := 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9157
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9158
    "/ 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
  9159
    "/ use table-value in loop
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9160
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9161
    greyValues := self greyMapForRange:(255 * 1024).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9162
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9163
    0 to:(h-1) do:[:y |
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9164
        nextDst := dstIndex + bytesPerMonoRow.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9165
        byte := 0.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9166
        bitCnt := 8.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9167
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9168
        t := errorArray.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9169
        errorArray := errorArray1.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9170
        errorArray1 := errorArray2.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9171
        errorArray2 := errorArray3.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9172
        errorArray3 := t.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9173
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9174
        errorArray3 atAllPut:0.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9175
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9176
        self valuesAtY:y from:0 to:(w-1) do:[:x :pixel |
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9177
            |eP eD|
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9178
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9179
            "/ get the colors grey value [0 .. 1]
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9180
            grey := greyValues at:(pixel + 1).
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9181
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9182
            "/ adjust error
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9183
            xE := x + 3 + 1.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9184
            grey := (grey + (errorArray at:xE)).
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9185
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9186
            byte := byte bitShift:1.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9187
            grey > (127 * 1024) ifTrue:[
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9188
                byte := byte bitOr:1.      "/ white
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9189
                e := grey - (255 * 1024)
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9190
            ] ifFalse:[
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9191
                e := grey                  "/ black
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9192
            ].
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9193
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9194
            e ~= 0 ifTrue:[
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9195
                "/ distribute the error:
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9196
                "/                  XX    32
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9197
                "/         12    26    30    16
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9198
                "/            12    26    12
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9199
                "/          5    12    12     5
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9200
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9201
                eD := e.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9202
                e := e // 200.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9203
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9204
                eP := e * 32. eD := eD - eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9205
                errorArray at:xE+2 put:(errorArray at:xE+2) + eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9206
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9207
                eP := e * 30. eD := eD - eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9208
                errorArray1 at:xE+1 put:(errorArray1 at:xE+1) + eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9209
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9210
                eP := e * 16. eD := eD - eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9211
                errorArray1 at:xE+3 put:(errorArray1 at:xE+3) + eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9212
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9213
                eP := e * 26. eD := eD - eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9214
                errorArray1 at:xE-1 put:(errorArray1 at:xE-1) + eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9215
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9216
                eD := eD - eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9217
                errorArray2 at:xE put:(errorArray2 at:xE) + eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9218
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9219
                eP := e * 12. eD := eD - eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9220
                errorArray1 at:xE-3 put:(errorArray1 at:xE-3) + eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9221
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9222
                eD := eD - eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9223
                errorArray2 at:xE-2 put:(errorArray2 at:xE-2) + eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9224
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9225
                eD := eD - eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9226
                errorArray2 at:xE+2 put:(errorArray2 at:xE+2) + eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9227
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9228
                eD := eD - eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9229
                errorArray3 at:xE-1 put:(errorArray3 at:xE-1) + eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9230
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9231
                eD := eD - eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9232
                errorArray3 at:xE+1 put:(errorArray3 at:xE+1) + eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9233
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9234
                eP := e * 5. eD := eD - eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9235
                errorArray3 at:xE-3 put:(errorArray3 at:xE-3) + eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9236
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9237
                eP := eD.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9238
                errorArray3 at:xE+3 put:(errorArray3 at:xE+3) + eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9239
            ].
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9240
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9241
            bitCnt := bitCnt - 1.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9242
            bitCnt == 0 ifTrue:[
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9243
                monoBits at:dstIndex put:byte.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9244
                dstIndex := dstIndex + 1.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9245
                byte := 0.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9246
                bitCnt := 8.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9247
            ].
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9248
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9249
        ].
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9250
        bitCnt ~~ 8 ifTrue:[
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9251
            byte := byte bitShift:bitCnt.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9252
            monoBits at:dstIndex put:byte.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9253
        ].
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9254
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9255
        dstIndex := nextDst.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9256
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9257
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9258
    ^ monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9259
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9260
    "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
  9261
    "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
  9262
! !
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9263
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9264
!Image methodsFor:'drawing'!
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9265
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9266
displayArcOrigin:origin corner:corner from:startAngle angle:angle withColor:aColor
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9267
    "draw a circle with some pixel value.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9268
     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
  9269
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9270
    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
  9271
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9272
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9273
     |cm i|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9274
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9275
     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
  9276
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9277
     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
  9278
     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
  9279
     i inspect.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9280
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9281
!
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9282
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9283
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
  9284
    "draw a circle with some pixel value.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9285
     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
  9286
     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
  9287
     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
  9288
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9289
    |tempForm wI "{ Class: SmallInteger }"
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9290
     hI "{ Class: SmallInteger }"|
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9291
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9292
    wI := self width.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9293
    hI := self height.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9294
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9295
    tempForm := Form width:wI height:hI depth:1 onDevice:Screen current.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9296
    tempForm clear.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9297
    tempForm paint:(Color colorId:1).
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9298
    tempForm displayArcOrigin:origin corner:corner from:startAngle angle:angle.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9299
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9300
    0 to:hI-1 do:[:yRun|
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9301
	0 to:wI-1 do:[:xRun|
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9302
	    (tempForm atX:xRun y:yRun) == 1 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9303
		self atImageAndMask:(xRun)@(yRun) putValue:aPixelValueOrNil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9304
	    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9305
	].
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9306
    ].
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9307
    self release. "/ device-image is no longer valid
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9308
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9309
    "
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9310
     |cm i|
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9311
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9312
     cm :=  Array with:Color white with:Color black with:Color red.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9313
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9314
     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
  9315
     i displayArcOrigin:100@100 corner:200@200 from:0 angle:90 withColor:Color red.
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9316
     i inspect.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9317
    "
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9318
!
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9319
4994
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9320
drawEllipse:aRectangle withColor:aColor
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9321
    "draw a circle with some pixel value.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9322
     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
  9323
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9324
    self drawEllipse:aRectangle withValue:(self valueFromColor:aColor)
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9325
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9326
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9327
     |cm i|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9328
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9329
     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
  9330
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9331
     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
  9332
     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
  9333
     i inspect.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9334
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9335
!
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9336
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9337
drawEllipse:aRectangle withValue:aPixelValueOrNil
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9338
    "draw a circle with some pixel value.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9339
     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
  9340
     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
  9341
     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
  9342
4994
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9343
    |tempForm xI "{ Class: SmallInteger }"
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9344
     yI "{ Class: SmallInteger }"
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9345
     wI "{ Class: SmallInteger }"
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9346
     hI "{ Class: SmallInteger }"|
4994
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9347
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9348
    wI := aRectangle width.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9349
    hI := aRectangle height.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9350
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9351
    tempForm := Form width:wI height:hI depth:1 onDevice:Screen current.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9352
    tempForm clear.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9353
    tempForm paint:(Color colorId:1).
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9354
    tempForm displayArcIn:(0@0 extent:wI@hI) from:0 angle:360.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9355
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9356
    xI := aRectangle left.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9357
    yI := aRectangle top.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9358
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9359
    0 to:hI-1 do:[:yRun|
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9360
	0 to:wI-1 do:[:xRun|
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9361
	    (tempForm atX:xRun y:yRun) == 1 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9362
		self atImageAndMask: (xI+xRun)@(yI+yRun) putValue:aPixelValueOrNil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9363
	    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9364
	].
4994
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9365
    ].
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9366
    self release. "/ device-image is no longer valid
4994
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9367
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9368
    "
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9369
     |cm i|
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9370
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9371
     cm :=  Array with:Color white with:Color black with:Color red.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9372
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9373
     i := Depth8Image extent:300@400 depth:8 palette:cm.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9374
     i drawEllipse:(0@0 corner:80@100) withColor:Color red.
4994
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9375
     i inspect.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9376
    "
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9377
!
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9378
5235
e9ab91666ebf *** empty log message ***
sr
parents: 5216
diff changeset
  9379
drawLineFrom:startPoint to:endPoint withColor:aColorOrPixelValue
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9380
    "draw a line with some pixel value.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9381
     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
  9382
     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
  9383
     (such as the HumanReadableImageGenerator)"
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9384
5235
e9ab91666ebf *** empty log message ***
sr
parents: 5216
diff changeset
  9385
    |pixelValue|
e9ab91666ebf *** empty log message ***
sr
parents: 5216
diff changeset
  9386
e9ab91666ebf *** empty log message ***
sr
parents: 5216
diff changeset
  9387
    pixelValue := aColorOrPixelValue.
e9ab91666ebf *** empty log message ***
sr
parents: 5216
diff changeset
  9388
    pixelValue isInteger ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9389
	pixelValue := self valueFromColor:aColorOrPixelValue
5235
e9ab91666ebf *** empty log message ***
sr
parents: 5216
diff changeset
  9390
    ].
e9ab91666ebf *** empty log message ***
sr
parents: 5216
diff changeset
  9391
    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
  9392
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9393
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9394
     |i|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9395
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9396
     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
  9397
     i photometric:#blackIs0.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9398
     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
  9399
     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
  9400
     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
  9401
     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
  9402
     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
  9403
     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
  9404
     i inspect.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9405
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9406
!
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9407
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9408
drawLineFrom:startPoint to:endPoint withValue:aPixelValueOrNil
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9409
    "draw a line with some pixel value.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9410
     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
  9411
     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
  9412
     (such as the HumanReadableImageGenerator).
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9413
     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
  9414
     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
  9415
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9416
    |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
  9417
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9418
    x0 := startPoint x.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9419
    y0 := startPoint y.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9420
    x1 := endPoint x.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9421
    y1 := endPoint y.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9422
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9423
    steep := (y1 - y0) abs > (x1 - x0) abs.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9424
    steep ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9425
	t := x0. x0 := y0. y0 := t.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9426
	t := x1. x1 := y1. y1 := t.
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9427
    ].
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9428
    x0 > x1 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9429
	t := x0. x0 := x1. x1 := t.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9430
	t := y0. y0 := y1. y1 := t.
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9431
    ].
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9432
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9433
    deltax := x1 - x0.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9434
    deltay := (y1 - y0) abs.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9435
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9436
    deltax == 0 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9437
	y0 to: y1 do:[:y |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9438
	    self atImageAndMask:x0@y putValue:aPixelValueOrNil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9439
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9440
	^ self.
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9441
    ].
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9442
    deltay == 0 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9443
	x0 to: x1 do:[:x |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9444
	    self atImageAndMask:x@y0 putValue:aPixelValueOrNil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9445
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9446
	^ self.
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9447
    ].
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9448
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9449
    error := 0.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9450
    deltaerr := deltay / deltax.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9451
    y := y0.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9452
    y0 < y1 ifTrue:[ ystep := 1 ] ifFalse:[ ystep := -1 ].
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9453
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9454
    x0 to: x1 do:[:x |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9455
	steep ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9456
	    self atImageAndMask:y@x putValue:aPixelValueOrNil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9457
	] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9458
	    self atImageAndMask:x@y putValue:aPixelValueOrNil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9459
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9460
	error := error + deltaerr.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9461
	error >= 0.5 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9462
	    y := y + ystep.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9463
	    error := error - 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9464
	]
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9465
    ].
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9466
    self release. "/ device-image is no longer valid
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9467
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9468
    "
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9469
     |i|
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9470
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9471
     i := Depth1Image extent:100@100 depth:1 palette:nil.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9472
     i photometric:#blackIs0.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9473
     i drawLineFrom:5@5 to:94@5 withColor:1.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9474
     i drawLineFrom:94@5 to:94@94 withColor:1.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9475
     i drawLineFrom:94@94 to:5@94 withColor:1.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9476
     i drawLineFrom:5@94 to:5@5 withColor:1.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9477
     i drawLineFrom:10@10 to:90@90 withColor:1.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9478
     i drawLineFrom:90@10 to:10@90 withColor:1.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9479
     i inspect.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9480
    "
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9481
!
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9482
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9483
drawRectangle: aRectangle withColor:aColor
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9484
    "draw a rectangle with some pixel value.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9485
     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
  9486
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9487
    self drawRectangle:aRectangle withValue:(self valueFromColor:aColor)
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9488
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9489
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9490
     |i|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9491
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9492
     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
  9493
     i photometric:#blackIs0.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9494
     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
  9495
     i inspect.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9496
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9497
!
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9498
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9499
drawRectangle: aRectangle withValue:aPixelValueOrNil
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9500
    "draw a rectangle with some pixel value.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9501
     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
  9502
     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
  9503
     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
  9504
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9505
    |xI "{ Class: SmallInteger }"
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9506
     yI "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9507
     wI "{ Class: SmallInteger }"
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9508
     hI "{ Class: SmallInteger }"|
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9509
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9510
    xI := aRectangle left.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9511
    yI := aRectangle top.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9512
    wI := aRectangle width.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9513
    hI := aRectangle height.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9514
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9515
    xI to:xI+wI-1 do:[:xRun|
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9516
	self atImageAndMask: xRun@yI put:aPixelValueOrNil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9517
	self atImageAndMask: xRun@(yI+hI-1) put:aPixelValueOrNil
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9518
    ].
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9519
    yI+1 to:yI+hI-2 do:[:yRun|
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9520
	self atImageAndMask: xI@yRun put:aPixelValueOrNil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9521
	self atImageAndMask: xI+wI-1@yRun put:aPixelValueOrNil
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9522
    ].
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9523
    self release. "/ device-image is no longer valid
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9524
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9525
    "
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9526
     |i|
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9527
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9528
     i := Depth1Image extent:100@100 depth:1 palette:nil.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9529
     i photometric:#blackIs0.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9530
     i drawRectangle:(10@10 corner:90@90) withColor:1.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9531
     i inspect.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9532
    "
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9533
!
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9534
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  9535
fillAntiAliasedArc:origin radius:r from:startAngle angle:angle withColor:aColor colorDictionary:colorDictionary blendStart:blendStart
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9536
    "draw a circle with some pixel value.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9537
     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
  9538
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9539
    |tempForm wI "{ Class: SmallInteger }"
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9540
     hI "{ Class: SmallInteger }"
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9541
     colorValue|
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9542
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9543
    wI := self width.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9544
    hI := self height.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9545
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9546
    tempForm := Form width:wI height:hI depth:1 onDevice:Screen current.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9547
    tempForm clear.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9548
    tempForm paint:(Color colorId:1).
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9549
    tempForm fillArc:origin radius:r from:startAngle angle:angle.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9550
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9551
    colorValue := self valueFromColor:aColor.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9552
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9553
    0 to:hI-1 do:[:yRun|
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9554
	0 to:wI-1 do:[:xRun|
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9555
	    (tempForm atX:xRun y:yRun) == 1 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9556
		self atImageAndMask:(xRun)@(yRun) putValue:colorValue.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9557
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9558
		#(#left right) do:[:aHorizontal |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9559
		    #(#top bottom) do:[:aVertical |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9560
			self vitualAntiAliasedAlongXvertical:aVertical horizontal:aHorizontal form:tempForm color:aColor xRun:xRun yRun:yRun colorDictionary:colorDictionary blendStart:blendStart.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9561
			self vitualAntiAliasedAlongYhorizontal:aHorizontal vertical:aVertical form:tempForm color:aColor xRun:xRun yRun:yRun colorDictionary:colorDictionary blendStart:blendStart.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9562
		    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9563
		].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9564
	    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9565
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9566
    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9567
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9568
    "
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9569
	|colorMap aaImgArray|
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9570
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9571
	colorMap := Array with:Color white with:Color black with:Color red with:Color blue.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9572
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9573
	aaImgArray := Depth8Image extent:300@400 depth:8 antiAliasedPalette:colorMap bgColor:Color white.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9574
	aaImgArray last fillAntiAliasedArc:205@195 radius:80 from:0 angle:90 withColor:Color red
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9575
	    colorDictionary:aaImgArray first
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9576
	    blendStart:aaImgArray second.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9577
	aaImgArray last fillAntiAliasedArc:200@200 radius:80 from:90 angle:270 withColor:Color blue
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9578
	    colorDictionary:aaImgArray first
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9579
	    blendStart:aaImgArray second.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9580
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9581
	aaImgArray last inspect.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9582
    "
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9583
!
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9584
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9585
fillArc:origin radius:r from:startAngle angle:angle withColor:aColorOrIndex
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9586
    "draw a circle with some pixel value.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9587
     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
  9588
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9589
    |tempForm wI "{ Class: SmallInteger }"
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9590
     hI "{ Class: SmallInteger }"
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9591
     colorValue|
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9592
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9593
    wI := self width.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9594
    hI := self height.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9595
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9596
    tempForm := Form width:wI height:hI depth:1 onDevice:Screen current.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9597
    tempForm clear.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9598
    tempForm paint:(Color colorId:1).
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9599
    tempForm fillArc:origin radius:r from:startAngle angle:angle.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9600
4997
15d53562d4e8 changed #fillArc:radius:from:angle:withColor:
sr
parents: 4996
diff changeset
  9601
    aColorOrIndex isInteger ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9602
	colorValue := aColorOrIndex.
4997
15d53562d4e8 changed #fillArc:radius:from:angle:withColor:
sr
parents: 4996
diff changeset
  9603
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9604
	colorValue := self valueFromColor:aColorOrIndex.
4997
15d53562d4e8 changed #fillArc:radius:from:angle:withColor:
sr
parents: 4996
diff changeset
  9605
    ].
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9606
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9607
    0 to:hI-1 do:[:yRun|
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9608
	0 to:wI-1 do:[:xRun|
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9609
	    (tempForm atX:xRun y:yRun) == 1 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9610
		self atImageAndMask:(xRun)@(yRun) putValue:colorValue.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9611
	    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9612
	].
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9613
    ].
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9614
    self release. "/ device-image is no longer valid
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9615
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9616
    "
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9617
     |cm i|
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9618
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9619
     cm :=  Array with:Color white with:Color black with:Color red with:Color blue.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9620
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9621
     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
  9622
     i fillArc:205@195 radius:80 from:0 angle:90 withColor:Color red.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9623
     i fillArc:200@200 radius:80 from:90 angle:270 withColor:Color blue.
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9624
     i inspect.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9625
    "
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9626
!
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9627
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9628
fillEllipse:aRectangle withColor:aColor
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9629
    "draw a circle with some pixel value.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9630
     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
  9631
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9632
    self fillEllipse:aRectangle withValue:(self valueFromColor:aColor)
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9633
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9634
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9635
     |cm i|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9636
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9637
     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
  9638
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9639
     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
  9640
     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
  9641
     i inspect.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9642
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9643
!
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9644
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9645
fillEllipse:aRectangle withValue:aPixelValueOrNil
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9646
    "draw a circle with some pixel value.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9647
     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
  9648
     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
  9649
     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
  9650
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9651
    |tempForm xI "{ Class: SmallInteger }"
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9652
     yI "{ Class: SmallInteger }"
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9653
     wI "{ Class: SmallInteger }"
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9654
     hI "{ Class: SmallInteger }"|
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9655
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9656
    wI := aRectangle width.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9657
    hI := aRectangle height.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9658
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9659
    tempForm := Form width:wI height:hI depth:1 onDevice:Screen current.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9660
    tempForm clear.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9661
    tempForm paint:(Color colorId:1).
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9662
    tempForm fillArcIn:(0@0 extent:wI@hI) from:0 angle:360.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9663
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9664
    xI := aRectangle left.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9665
    yI := aRectangle top.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9666
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9667
    0 to:hI-1 do:[:yRun|
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9668
	0 to:wI-1 do:[:xRun|
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9669
	    (tempForm atX:xRun y:yRun) == 1 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9670
		self atImageAndMask:(xI+xRun)@(yI+yRun) putValue:aPixelValueOrNil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9671
	    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9672
	].
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9673
    ].
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9674
    self release. "/ device-image is no longer valid
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9675
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9676
    "
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9677
     |cm i|
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9678
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9679
     cm :=  Array with:Color white with:Color black with:Color red.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9680
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9681
     i := Depth8Image extent:300@400 depth:8 palette:cm.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9682
     i fillEllipse:(0@0 corner:80@100) withColor:Color red.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9683
     i inspect.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9684
    "
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9685
!
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9686
4995
3a5cb7a57b0b changed #fillRectangle:aRectangle withColor:aColor
sr
parents: 4994
diff changeset
  9687
fillRectangle:aRectangle withColor:aColor
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9688
    self
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9689
	fillRectangle:aRectangle
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9690
	withValue:(self valueFromColor:aColor)
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9691
!
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9692
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9693
fillRectangle:aRectangle withValue:aPixelValueOrNil
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9694
    "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
  9695
     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
  9696
     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
  9697
     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
  9698
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9699
    self
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9700
	fillRectangleX:aRectangle left y:aRectangle top
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9701
	width:aRectangle width height:aRectangle height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9702
	withValue:aPixelValueOrNil
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9703
!
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9704
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9705
fillRectangleX:x y:y width:w height:h with:aColor
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9706
    "fill a rectangular area with a aColor"
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9707
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9708
    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
  9709
!
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  9710
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9711
fillRectangleX:x y:y width:w height:h withValue:aPixelValueOrNil
1630
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  9712
    "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
  9713
     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
  9714
     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
  9715
     otherwise to 1. (used by the bitmap editor)"
1630
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  9716
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  9717
    |xI "{ Class: SmallInteger }"
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9718
     yI "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9719
     wI "{ Class: SmallInteger }"
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9720
     hI "{ Class: SmallInteger }"
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9721
     p|
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9722
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9723
    xI := x.
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9724
    yI := y.
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9725
    wI := w.
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9726
    hI := h.
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9727
    p := Point new.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9728
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9729
    yI to:yI+hI-1 do:[:yRun |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9730
	xI to:xI+wI-1 do:[:xRun |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9731
	    p x:xRun y:yRun.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9732
	    self atImageAndMask:p putValue:aPixelValueOrNil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9733
	]
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9734
    ].
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9735
    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
  9736
1630
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  9737
    "Created: 22.4.1997 / 14:02:14 / cg"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9738
    "Modified: 24.4.1997 / 17:24:58 / cg"
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9739
!
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9740
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9741
floodFillAt: aPoint withColor: aColor
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9742
    "fill a area with aColor like a flood up to surrounded pixels having different colors.
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9743
     By using #atImageAndMask:put: it also works on images with mono masks."
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9744
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9745
    self floodFillAt:aPoint withValue:(self valueFromColor:aColor)
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9746
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9747
"/    |surroundingPixelsOfDo detectedPixel processPixelToFill
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9748
"/     allDetectedPixelCoordinates enumerateDetectedPixelsAndDo
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9749
"/     toDo idx pixel w h|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9750
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9751
"/    w := self width.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9752
"/    h := self height.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9753
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9754
"/    surroundingPixelsOfDo :=
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9755
"/        [:pX :pY :fn |
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9756
"/            |nX nY|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9757
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9758
"/            nX := pX + 1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9759
"/            nY := pY + 1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9760
"/            (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
  9761
"/            (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
  9762
"/            (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
  9763
"/            (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
  9764
"/        ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9765
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9766
"/    enumerateDetectedPixelsAndDo :=
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9767
"/        [:detectedPixels :action |
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9768
"/            |idx|
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
"/            idx := 1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9771
"/            0 to:h-1 do:[:y |
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9772
"/                0 to:w-1 do:[:x |
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9773
"/                    (detectedPixels at:idx) ifTrue:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9774
"/                        action value:x value:y
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9775
"/                    ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9776
"/                    idx := idx + 1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9777
"/                ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9778
"/            ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9779
"/        ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9780
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9781
"/    processPixelToFill := [:spX :spY |
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9782
"/            |sp idx|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9783
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9784
"/            ((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
  9785
"/            ifTrue: [
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9786
"/                idx := 1 + spX + (spY * w).
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9787
"/                (allDetectedPixelCoordinates at:idx) ifFalse:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9788
"/                    allDetectedPixelCoordinates at:idx put:true.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9789
"/                    toDo add:spX @ spY.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9790
"/                ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9791
"/            ]
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9792
"/        ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9793
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9794
"/    (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
  9795
"/        allDetectedPixelCoordinates := mask floodFillAt: aPoint withColor: Color white.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9796
"/        enumerateDetectedPixelsAndDo
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9797
"/                value:allDetectedPixelCoordinates
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9798
"/                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
  9799
"/        ^ allDetectedPixelCoordinates
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9800
"/    ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9801
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9802
"/    detectedPixel := self pixelAt: aPoint.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9803
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9804
"/    allDetectedPixelCoordinates := BooleanArray new:(w * h).
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9805
"/    toDo := OrderedCollection new:1000.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9806
"/    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
  9807
"/    toDo add:aPoint.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9808
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9809
"/    [toDo notEmpty] whileTrue:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9810
"/        |p|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9811
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9812
"/        p := toDo removeFirst.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9813
"/        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
  9814
"/    ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9815
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9816
"/    idx := 1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9817
"/    aColor redByte notNil ifTrue:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9818
"/        pixel := self valueFromColor:aColor.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9819
"/    ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9820
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9821
"/    pixel isNil ifTrue:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9822
"/        enumerateDetectedPixelsAndDo
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9823
"/                value:allDetectedPixelCoordinates
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9824
"/                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
  9825
"/    ] ifFalse:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9826
"/        enumerateDetectedPixelsAndDo
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9827
"/                value:allDetectedPixelCoordinates
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9828
"/                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
  9829
"/    ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9830
"/    ^ allDetectedPixelCoordinates
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9831
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9832
    "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
  9833
!
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9834
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9835
floodFillAt:aPoint withValue:aPixelValueOrNil
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9836
    "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
  9837
     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
  9838
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9839
    |surroundingPixelsOfDo detectedPixel detectedMask processPixelToFill
3861
e9cbd4ec6020 flood fill with mask fixed
Claus Gittinger <cg@exept.de>
parents: 3860
diff changeset
  9840
     allDetectedPixelCoordinates enumerateDetectedPixelsAndDo
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9841
     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
  9842
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  9843
    w := self width.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  9844
    h := self height.
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9845
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9846
    surroundingPixelsOfDo :=
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9847
	[:pX :pY :fn |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9848
	    |nX nY|
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9849
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9850
	    nX := pX + 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9851
	    nY := pY + 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9852
	    (nY < h) ifTrue: [fn value:pX value:nY].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9853
	    (pY > 0) ifTrue: [fn value:pX value:(pY - 1)].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9854
	    (nX < w) ifTrue: [fn value:nX value:pY].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9855
	    (pX > 0) ifTrue: [fn value:(pX - 1) value:pY].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9856
	].
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9857
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9858
    enumerateDetectedPixelsAndDo :=
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9859
	[:detectedPixels :action |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9860
	    |idx|
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9861
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9862
	    idx := 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9863
	    0 to:h-1 do:[:y |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9864
		0 to:w-1 do:[:x |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9865
		    (detectedPixels at:idx) ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9866
			action value:x value:y
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9867
		    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9868
		    idx := idx + 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9869
		].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9870
	    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9871
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9872
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9873
    processPixelToFill :=
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9874
	[:spX :spY |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9875
	    |samePixel sp idx|
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9876
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9877
	    mask isNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9878
		samePixel := (self pixelAtX:spX y:spY) == detectedPixel
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9879
	    ] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9880
		detectedMask == 0 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9881
		    samePixel := (mask pixelAtX:spX y:spY) == 0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9882
		] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9883
		    samePixel := ((self pixelAtX:spX y:spY) == detectedPixel)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9884
				 and:[ (mask pixelAtX:spX y:spY) == detectedMask ]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9885
		].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9886
	    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9887
	    samePixel ifTrue: [
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9888
		idx := 1 + spX + (spY * w).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9889
		(allDetectedPixelCoordinates at:idx) ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9890
		    allDetectedPixelCoordinates at:idx put:true.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9891
		    toDo add:spX @ spY.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9892
		].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9893
	    ]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9894
	].
5138
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
"/    (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
  9897
"/        allDetectedPixelCoordinates := mask floodFillAt: aPoint withColor: Color white.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9898
"/        enumerateDetectedPixelsAndDo
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9899
"/                value:allDetectedPixelCoordinates
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9900
"/                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
  9901
"/        ^ allDetectedPixelCoordinates
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9902
"/    ].
3759
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  9903
2205
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  9904
    detectedPixel := self pixelAt: aPoint.
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9905
    mask isNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9906
	detectedMask := 1
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9907
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9908
	detectedMask := mask pixelAt: aPoint.
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9909
    ].
4420
6b8505b72ae6 flood-filling of 24-bit images
Claus Gittinger <cg@exept.de>
parents: 4418
diff changeset
  9910
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9911
    allDetectedPixelCoordinates := BooleanArray new:(w * h).
3759
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  9912
    toDo := OrderedCollection new:1000.
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9913
    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
  9914
    toDo add:aPoint.
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  9915
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  9916
    [toDo notEmpty] whileTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9917
	|p|
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9918
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9919
	p := toDo removeLast.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9920
	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
  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
    aPixelValueOrNil isNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9924
	drawAction := [:x :y |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9925
			       mask pixelAtX:x y:y put:0.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9926
			       self pixelAtX:x y:y put:0.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9927
		      ].
3805
d87c919fb2a7 oops - care for filling a mask
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  9928
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9929
	drawAction := [:x :y |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9930
				mask notNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9931
				    mask pixelAtX:x y:y put:1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9932
				].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9933
				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
  9934
    ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9935
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9936
    enumerateDetectedPixelsAndDo
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9937
	value:allDetectedPixelCoordinates
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9938
	value:drawAction.
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9939
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9940
    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
  9941
    ^ allDetectedPixelCoordinates
2205
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  9942
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  9943
    "Modified: / 29.7.1998 / 03:09:16 / cg"
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9944
!
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9945
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9946
rectangle: aRectangle withColor:aColor
5216
f7ec910cfce1 Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 5200
diff changeset
  9947
    <resource: #obsolete>
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9948
    "draw a rectangle with some pixel value.
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9949
    By using #atImageAndMask:put: it also works on images with mono masks."
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9950
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9951
    self obsoleteMethodWarning.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9952
    self drawRectangle: aRectangle withColor:aColor
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9953
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9954
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9955
! !
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9956
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9957
!Image methodsFor:'enumerating'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9958
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9959
atY:y from:x1 to:x2 do:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9960
    "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
  9961
     The block is passed the color at each pixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9962
     The code here provides a generic and slow implementation, and
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9963
     should be redefined in concrete subclasses, to avoid some processing
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9964
     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
  9965
     and also the color allocation)."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9966
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  9967
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  9968
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9969
    self obsoleteMethodWarning:'use #colorsAtY:from:to:do:'.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9970
    self colorsAtY:y from:x1 to:x2 do:aBlock
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9971
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9972
    "Modified: 7.6.1996 / 19:13:30 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9973
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9974
5143
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9975
colorsAtX:x from:y1 to:y2 do:aBlock
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9976
    "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
  9977
     The block is passed the color at each pixel.
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9978
     The code here provides a generic and slow implementation, and
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9979
     should be redefined in concrete subclasses, to avoid some processing
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9980
     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
  9981
     and also the color allocation)."
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9982
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9983
    |yStart "{Class: SmallInteger }"
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9984
     yEnd   "{Class: SmallInteger }"|
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9985
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9986
    yStart := y1.
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9987
    yEnd := y2.
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9988
    yStart to:yEnd do:[:yRun |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9989
	aBlock value:yRun value:(self colorAtX:x y:yRun)
5143
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9990
    ]
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9991
!
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9992
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9993
colorsAtY:y from:x1 to:x2 do:aBlock
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9994
    "perform aBlock for each pixel from x1 to x2 in row y.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9995
     The block is passed the color at each pixel.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9996
     The code here provides a generic and slow implementation, and
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9997
     should be redefined in concrete subclasses, to avoid some processing
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9998
     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
  9999
     and also the color allocation)."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10000
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10001
    |xStart "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10002
     xEnd   "{Class: SmallInteger }"|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10003
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10004
    xStart := x1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10005
    xEnd := x2.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10006
    xStart to:xEnd do:[:xRun |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10007
	aBlock value:xRun value:(self colorAtX:xRun y:y)
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10008
    ]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10009
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
 10010
    "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
 10011
    "Modified: / 30.9.1998 / 22:14:16 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10012
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10013
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10014
colorsFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10015
    "perform aBlock for each color in a rectangular area of the image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10016
     Notice, that x and y coordinates start at 0@0 for the upper left corner.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10017
     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
 10018
     The code here provides a generic and slow implementation, and
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10019
     should be redefined in concrete subclasses, to avoid some processing
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10020
     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
 10021
     and especially, the color allocations)."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10022
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 10023
    |yS "{Class: SmallInteger }"
942
5e45da3c19d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
 10024
     yE "{Class: SmallInteger }"
5e45da3c19d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
 10025
     yR|
5e45da3c19d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
 10026
5e45da3c19d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
 10027
    yS := yStart.
5e45da3c19d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
 10028
    yE := yEnd.
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 10029
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10030
    yS to:yE do:[:yRun |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10031
	yR := yRun.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10032
	self colorsAtY:yRun from:xStart to:xEnd do:[:xRun :color |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10033
	    aBlock value:xRun value:yR value:color
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10034
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10035
    ]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10036
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 10037
    "Modified: 11.7.1996 / 19:50:47 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10038
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10039
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10040
valueAtY:y from:x1 to:x2 do:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10041
    "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
 10042
     Obsolete - remains for backward compatibility."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10043
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
 10044
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
 10045
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10046
    self obsoleteMethodWarning:'use #valuesAtY:from:to:do:'.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10047
    self valuesAtY:y from:x1 to:x2 do:aBlock
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10048
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10049
    "Modified: 7.6.1996 / 19:11:06 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10050
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10051
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10052
valuesAtY:y from:x1 to:x2 do:aBlock
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10053
    "WARNING: for now, this enumerates pixel values
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10054
     (backward compatibility with ST/X)
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10055
     In the future, this will enumerate colors
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10056
     Use #pixelAtT:from:to:do: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10057
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10058
     perform aBlock for each pixelValue from x1 to x2 in row y.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10059
     Notice, that x and y coordinates start at 0@0 for the upper left corner.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10060
     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
 10061
     (see also Image>>atY:from:to:do:).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10062
     The code here provides a generic and slow implementation, and
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10063
     should be redefined in concrete subclasses, to avoid some processing
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10064
     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
 10065
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10066
    |xStart "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10067
     xEnd   "{Class: SmallInteger }"|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10068
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10069
    xStart := x1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10070
    xEnd := x2.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10071
    xStart to:xEnd do:[:xRun |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10072
	aBlock value:xRun value:(self pixelAtX:xRun y:y)
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10073
    ]
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10074
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10075
    "Created: 7.6.1996 / 19:09:51 / cg"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10076
    "Modified: 24.4.1997 / 16:55:38 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10077
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10078
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10079
valuesFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10080
    "perform aBlock for each pixelValue in a rectangular area of the image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10081
     Notice, that x and y coordinates start at 0@0 for the upper left corner.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10082
     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
 10083
     The code here provides a generic and slow implementation, and
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10084
     should be redefined in concrete subclasses, to avoid some processing
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10085
     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
 10086
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10087
    |xS "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10088
     xE "{Class: SmallInteger }"|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10089
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10090
    xS := xStart.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10091
    xE := xEnd.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10092
    yStart to:yEnd do:[:yRun |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10093
	self valuesAtY:yRun from:xStart to:xEnd do:[:xRun :pixel |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10094
	    aBlock value:xRun value:yRun value:pixel
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10095
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10096
    ]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10097
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10098
    "Modified: 7.6.1996 / 19:09:29 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 10099
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
 10100
3613
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10101
!Image methodsFor:'finalization'!
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10102
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10103
finalizationLobby
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10104
    "answer the registry used for finalization.
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10105
     Images have their own Registry"
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10106
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10107
    ^ Lobby
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10108
!
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10109
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10110
finalize
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10111
    "some Image has been collected - nothing to do"
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10112
! !
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10113
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 10114
!Image methodsFor:'image manipulations'!
48194c26a46c Initial revision
claus
parents:
diff changeset
 10115
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10116
applyPixelValuesTo:pixelFunctionBlock in:aRectangle into:newImage
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 10117
    "helper for withPixelFunctionAppliedToValues:
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 10118
     enumerate pixelValues and evaluate the block for each.
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10119
     Could be redefined by subclasses for better performance."
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10120
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10121
    |w   "{Class: SmallInteger }"
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10122
     h   "{Class: SmallInteger }"
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10123
     x0  "{Class: SmallInteger }"
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10124
     y0  "{Class: SmallInteger }"
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10125
     y   "{Class: SmallInteger }"
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10126
     newPixel newPixelRow pixelRow|
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10127
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10128
    x0 := aRectangle left.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10129
    y0 := aRectangle top.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10130
    w := aRectangle width.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10131
    h := aRectangle height.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10132
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10133
    newPixelRow := Array new:w.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10134
    pixelRow := self pixelArraySpecies new:width.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10135
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10136
    (x0 = 0 and:[w = self width]) ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10137
	"/ slightly faster
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10138
	y := y0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10139
	h timesRepeat:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10140
	    self rowAt:y into:pixelRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10141
	    1 to:w do:[:runCol |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10142
		newPixel := pixelFunctionBlock
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10143
				value:self
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10144
				value:(pixelRow at:runCol)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10145
				value:(runCol-1)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10146
				value:y.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10147
		newPixelRow at:runCol put:newPixel.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10148
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10149
	    newImage rowAt:y putAll:newPixelRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10150
	    y := y + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10151
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10152
	^ self.
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10153
    ].
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10154
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10155
    y := y0.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10156
    h timesRepeat:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10157
	self rowAt:y into:pixelRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10158
	1 to:w do:[:runCol |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10159
	    newPixel := pixelFunctionBlock
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10160
			    value:self
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10161
			    value:(pixelRow at:runCol+x0)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10162
			    value:(runCol+x0-1)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10163
			    value:y.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10164
	    newPixelRow at:runCol put:newPixel.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10165
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10166
	pixelRow replaceFrom:x0+1 to:x0+1+w-1 with:newPixelRow startingAt:1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10167
	newImage rowAt:y putAll:pixelRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10168
	y := y + 1.
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10169
    ].
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10170
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10171
    "Modified: 24.4.1997 / 16:18:31 / cg"
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10172
!
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10173
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10174
applyPixelValuesTo:pixelFunctionBlock into:newImage
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10175
    "helper for withPixelFunctionAppliedToValues:
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10176
     enumerate pixelValues and evaluate the block for each."
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10177
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10178
    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10179
	applyPixelValuesTo:pixelFunctionBlock
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10180
	in:(0@0 corner:width@height)
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10181
	into:newImage
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10182
!
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10183
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10184
blendWith:aColor
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10185
    "return a new image which is blended with some color.
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10186
     The receiver must be a palette image (currently).
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10187
     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
 10188
     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
 10189
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10190
     ^ self
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10191
	copyWithColorMapProcessing:[:clr | clr blendWith:aColor]
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10192
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10193
    "
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10194
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10195
     ((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
 10196
     ((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
 10197
     ((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
 10198
    "
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10199
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10200
    "Modified: 24.4.1997 / 18:31:23 / cg"
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10201
!
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10202
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10203
colorMapProcessing:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10204
    "a helper for all kinds of colormap manipulations.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10205
     The argument, aBlock is called for every colormap entry,
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10206
     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
 10207
     This will fail for non-palette images.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10208
     See examples in Image>>copyWithColorMapProcessing:"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10209
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10210
    |nColors "{ Class: SmallInteger }"|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10211
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10212
    colorMap isNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10213
	self colorsFromX:0 y:0 toX:(self width-1) y:(self height-1) do:[:x :y :clr |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10214
	    self colorAtX:x y:y put:(aBlock value:clr)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10215
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10216
	^ self
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10217
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10218
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10219
    nColors := colorMap size.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10220
    1 to:nColors do:[:index |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10221
	|clr|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10222
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10223
	clr := colorMap at:index.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10224
	clr notNil ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10225
	    colorMap at:index put:(aBlock value:clr)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10226
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10227
    ]
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10228
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10229
    "Modified: 23.4.1996 / 11:13:55 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10230
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10231
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10232
copyWithColorMapProcessing:aBlock
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10233
    "a helper to create & return new images based on the receiver with
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10234
     some colorMap processing. The receiver is copied, and the copied images
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10235
     colormap is modified by replacing entries with the result of the processing block,
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10236
     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
 10237
     a color.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10238
     CAVEAT: this only works with palette images (i.e. not for rgb or greyScale)"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10239
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10240
    |newImage|
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10241
4414
2c0f2ca53156 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
 10242
    self colorMap isNil ifTrue:[
6653
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10243
        ^ self withPixelFunctionApplied:[:orig :clr :x :y | aBlock  value:clr]
4414
2c0f2ca53156 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
 10244
"/        self error:'no colormap in image'.
2c0f2ca53156 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
 10245
"/        ^ nil
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10246
    ].
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10247
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10248
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10249
     the code below manipulates the colormap.
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10250
     For non-palette images, special code is required
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10251
    "
4414
2c0f2ca53156 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
 10252
    newImage := self copy.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10253
    newImage colorMapProcessing:aBlock.
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10254
    ^ newImage
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10255
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10256
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10257
     leave red component only:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10258
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10259
     (Image fromFile:'goodies/bitmaps/gifImages/claus.gif')
6653
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10260
        copyWithColorMapProcessing:[:clr | Color red:(clr red) green:0 blue:0]
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10261
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10262
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10263
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10264
     make it reddish:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10265
6653
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10266
     |img imgYellow imgGreen imgBlue|
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10267
     img := (Image fromFile:'../../../expeccoNET/server/data/images/styles/eXept/defects.gif').
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10268
     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
 10269
     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
 10270
     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
 10271
     imgBlue
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10272
    "
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10273
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10274
    "
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10275
     make it reddish:
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10276
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10277
     (Image fromFile:'../../goodies/bitmaps/gifImages/claus.gif')
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10278
        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
 10279
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10280
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10281
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10282
     invert:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10283
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10284
     (Image fromFile:'bitmaps/gifImages/claus.gif')
6653
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10285
        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
 10286
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10287
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10288
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10289
     lighter:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10290
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10291
     (Image fromFile:'bitmaps/gifImages/claus.gif')
6653
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10292
        copyWithColorMapProcessing:[:clr | |r g b|
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10293
                                                r := clr red.  g := clr green.  b := clr blue.
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10294
                                                Color red:(r + (100-r//2))
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10295
                                                      green:(g + (100-g//2))
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10296
                                                      blue:(b + (100-b//2))]
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10297
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10298
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10299
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10300
     darker:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10301
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10302
     (Image fromFile:'bitmaps/gifImages/claus.gif')
6653
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10303
        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
 10304
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10305
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10306
    "Modified: 24.4.1997 / 18:28:05 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10307
!
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10308
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10309
createMask
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10310
    |maskArray bytesPerMaskRow|
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10311
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10312
    bytesPerMaskRow := (width+7) // 8.
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10313
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10314
    maskArray := ByteArray new:(bytesPerMaskRow * height) withAll:2r11111111.
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10315
    mask := ImageMask width:width height:height fromArray:maskArray.
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10316
    ^ mask
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10317
!
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10318
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10319
darkened
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10320
    "return a new image which is slightly darker than the receiver.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10321
     The receiver must be a palette image (currently).
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10322
     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
 10323
     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
 10324
5655
37bd5c7eb765 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 5643
diff changeset
 10325
     ^ self copyWithColorMapProcessing:[:clr | clr darkened]
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10326
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10327
    "
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10328
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10329
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') darkened inspect
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10330
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10331
5655
37bd5c7eb765 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 5643
diff changeset
 10332
    "Modified: / 24-11-2010 / 11:06:58 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10333
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10334
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10335
easyRotateBitsInto:destinationImage angle:degrees
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10336
    "helper for rotation - does the actual pixel shuffling.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10337
     by degrees clockwise. Here, only 90, 180 and 270 degrees
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10338
     are implemented. Hard angles are done in #hardRotate:.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10339
     The code here is depth-independent (but not too fast);
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10340
     can be redefined in subclasses for more performance"
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10341
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10342
    |w  "{Class: SmallInteger }"
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10343
     h  "{Class: SmallInteger }"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10344
     c2 r2 pixelArray|
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10345
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10346
    w := width - 1.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10347
    h := height - 1.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10348
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10349
    pixelArray := self pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10350
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10351
    degrees = 90 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10352
	0 to:h do:[:row |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10353
	    self rowAt:row into:pixelArray startingAt:1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10354
	    c2 := h-row.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10355
	    0 to:w do:[:col |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10356
		destinationImage pixelAtX:c2 y:col put:(pixelArray at:(col+1)).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10357
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10358
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10359
	^ self.
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10360
    ].
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10361
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10362
    degrees = 180 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10363
	0 to:h do:[:row |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10364
	    self rowAt:row into:pixelArray startingAt:1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10365
	    r2 := h - row.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10366
	    0 to:w do:[:col |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10367
		destinationImage pixelAtX:(w-col) y:r2 put:(pixelArray at:(col+1)).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10368
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10369
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10370
	^ self
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10371
    ].
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10372
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10373
    "/ degrees = 270
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10374
    0 to:h do:[:row |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10375
	self rowAt:row into:pixelArray startingAt:1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10376
	0 to:w do:[:col |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10377
	    destinationImage pixelAtX:row y:(w-col) put:(pixelArray at:(col+1)).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10378
	]
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10379
    ]
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10380
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10381
    "Created: 23.4.1997 / 14:36:45 / cg"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10382
    "Modified: 24.4.1997 / 17:26:26 / cg"
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
 10383
!
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10384
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10385
flipHorizontal
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10386
    "destructively inplace horizontal flip"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10387
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10388
    |h  "{Class: SmallInteger }"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10389
     pixelArray|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10390
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10391
    h := height - 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10392
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10393
    pixelArray := self pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10394
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10395
    0 to:h do:[:row |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10396
	self rowAt:row into:pixelArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10397
	pixelArray reverse.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10398
	self rowAt:row putAll:pixelArray.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10399
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10400
1386
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
 10401
    mask notNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10402
	mask flipHorizontal
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10403
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10404
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10405
    "/ flush device info
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 10406
    self release
1386
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
 10407
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10408
    "
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10409
     (Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') flipHorizontal inspect
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10410
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10411
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10412
    "Modified: 24.4.1997 / 18:29:13 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10413
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10414
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10415
flipVertical
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10416
    "inplace vertical flip"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10417
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10418
    |h           "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10419
     bytesPerRow "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10420
     buffer
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10421
     indexLow    "{Class: SmallInteger }"
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 10422
     indexHi     "{Class: SmallInteger }"
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 10423
     bytes|
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 10424
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 10425
    bytes := self bits.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10426
    bytesPerRow := self bytesPerRow.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10427
    buffer := ByteArray new:bytesPerRow.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10428
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10429
    h := height - 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10430
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10431
    indexLow := 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10432
    indexHi := bytesPerRow * h + 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10433
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10434
    0 to:(h // 2) do:[:row |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10435
	buffer replaceFrom:1 to:bytesPerRow with:bytes startingAt:indexLow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10436
	bytes replaceFrom:indexLow to:(indexLow + bytesPerRow - 1) with:bytes startingAt:indexHi.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10437
	bytes replaceFrom:indexHi to:(indexHi + bytesPerRow - 1) with:buffer startingAt:1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10438
	indexLow := indexLow + bytesPerRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10439
	indexHi := indexHi - bytesPerRow.
1386
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
 10440
    ].
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
 10441
    mask notNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10442
	mask flipVertical
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10443
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10444
    "flush device info"
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 10445
    self release
1386
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
 10446
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10447
    "
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10448
     (Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') flipVertical inspect
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10449
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10450
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10451
    "Modified: 24.4.1997 / 18:29:36 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10452
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10453
1739
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10454
hardAntiAliasedMagnifiedBy:scalePoint
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10455
    "return a new image magnified and antiAliased by scalePoint, aPoint.
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10456
     This converts into a depth24Image before doing the antiAlias-magnify.
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10457
     It is definitely slower than the non antiAliasing/integral magnification methods."
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10458
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10459
    ^ (Depth24Image fromImage:self)
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10460
	hardAntiAliasedMagnifiedBy:scalePoint
1739
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10461
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10462
    "Modified: 2.6.1997 / 13:19:57 / cg"
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10463
    "Created: 2.6.1997 / 15:53:34 / cg"
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10464
!
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10465
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10466
hardMagnifiedBy:scalePoint
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10467
    "return a new image magnified by scalePoint, aPoint.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10468
     This is the general magnification method, handling non-integral values.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10469
     It is slower than the integral magnification method."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10470
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10471
    |mX
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10472
     mY
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10473
     newWidth  "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10474
     newHeight "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10475
     w         "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10476
     h         "{ Class: SmallInteger }"
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 10477
     newImage newBits bitsPerPixel newBytesPerRow newMask
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10478
     value
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10479
     srcRow pixelArray|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10480
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10481
    mX := scalePoint x.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10482
    mY := scalePoint y.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10483
    ((mX < 0) or:[mY < 0]) ifTrue:[^ nil].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10484
    ((mX = 1) and:[mY = 1]) ifTrue:[^ self].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10485
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10486
    newWidth := (width * mX) truncated.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10487
    newHeight := (height * mY) truncated.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10488
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10489
    bitsPerPixel := self depth.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10490
    newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10491
    newBits := ByteArray uninitializedNew:(newBytesPerRow * newHeight).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10492
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 10493
    mask notNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10494
	newMask := (mask magnifiedBy:scalePoint)
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 10495
    ].
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 10496
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10497
    newImage := self species new.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10498
    newImage
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10499
	width:newWidth
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10500
	height:newHeight
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10501
	photometric:photometric
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10502
	samplesPerPixel:samplesPerPixel
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10503
	bitsPerSample:bitsPerSample
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10504
	colorMap:colorMap copy
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10505
	bits:newBits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10506
	mask:newMask.
905
228d503775d9 everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents: 904
diff changeset
 10507
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10508
    "walk over destination image fetching pixels from source image"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10509
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10510
    w := newWidth - 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10511
    h := newHeight - 1.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10512
    pixelArray := newImage pixelArraySpecies new:newWidth.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10513
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10514
    0 to:h do:[:row |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10515
	srcRow := (row // mY).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10516
	0 to:w do:[:col |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10517
	    value := self pixelAtX:(col // mX) y:srcRow.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10518
	    pixelArray at:(col+1) put:value.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10519
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10520
	newImage rowAt:row putAll:pixelArray.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10521
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10522
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10523
    ^ newImage
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10524
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10525
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10526
     |i|
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10527
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10528
     Time millisecondsToRun:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10529
	 i := i hardMagnifiedBy:0.5@0.5
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10530
     ].
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10531
     i
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10532
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10533
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10534
    "Modified: 24.4.1997 / 18:30:24 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10535
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10536
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10537
hardRotated:degrees
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10538
    "return a new image from the old one, by rotating the image
4953
b5017336aa26 comment
Claus Gittinger <cg@exept.de>
parents: 4952
diff changeset
 10539
     degrees clockwise (around its center).
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10540
     Warning: the returned image will be larger than the original image."
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10541
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10542
    |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
 10543
     newImage
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10544
     newWidth  "{ Class: SmallInteger }"
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10545
     newHeight "{ Class: SmallInteger }"
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10546
     newBytesPerRow newBits
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10547
     blackPixel halfW halfH radians m t bad
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10548
     bytesPerRow myDepth maskBits
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10549
     pX pY srcX srcY pix nX nY
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10550
     sinRot cosRot sinPY cosPY|
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10551
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 10552
    radians := degrees degreesToRadians.
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 10553
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10554
    "/ placing the image at the origin,
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10555
    "/ compute the diagonal and angle.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10556
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10557
    p := (width - 1 / 2) @ (height - 1 / 2).
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10558
    r := p r.
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 10559
    a := p theta.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10560
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10561
    "/ add the rotation
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10562
    "/ (sight - subtract, we defined things clockwise ...
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10563
    "/  ... in contrast to point which thinks counter-clockwise)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10564
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 10565
    aN := a - radians.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10566
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10567
    "/ compute new corner points
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 10568
    p1 := Point r:r theta:aN.         "/ rotated topRight
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 10569
    p2 := Point r:r theta:aN-a-a.     "/ rotated bottomRight
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10570
    p3 := p1 * -1.                    "/ rotated bottomLeft
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10571
    p4 := p2 * -1.                    "/ rotated topLeft
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10572
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10573
    "/ compute the boundary of the new image
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10574
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10575
    maxX := minX := p1 x.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10576
    (t := p2 x) > maxX ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10577
	maxX := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10578
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10579
	t < minX ifTrue:[minX := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10580
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10581
    (t := p3 x) > maxX ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10582
	maxX := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10583
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10584
	t < minX ifTrue:[minX := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10585
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10586
    (t := p4 x) > maxX ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10587
	maxX := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10588
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10589
	t < minX ifTrue:[minX := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10590
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10591
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10592
    maxY := minY := p1 y.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10593
    (t := p2 y) > maxY ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10594
	maxY := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10595
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10596
	t < minY ifTrue:[minY := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10597
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10598
    (t := p3 y) > maxY ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10599
	maxY := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10600
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10601
	t < minY ifTrue:[minY := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10602
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10603
    (t := p4 y) > maxY ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10604
	maxY := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10605
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10606
	t < minY ifTrue:[minY := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10607
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10608
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10609
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10610
    newWidth := (maxX - minX) rounded + 1.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10611
    newHeight := (maxY - minY) rounded + 1.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10612
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10613
    newImage := self species new.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10614
    newImage width:newWidth.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10615
    newImage height:newHeight.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10616
    newBytesPerRow := newImage bytesPerRow.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 10617
    newImage createPixelStore.
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 10618
    newBits := newImage bits.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10619
    newImage photometric:photometric.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10620
    newImage samplesPerPixel:samplesPerPixel.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10621
    newImage bitsPerSample:bitsPerSample.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10622
    newImage colorMap:colorMap copy.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10623
    newImage maskedPixelsAre0:maskedPixelsAre0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10624
    mask notNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10625
	newImage mask:(mask rotated:degrees)
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10626
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10627
	self isMask ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10628
	    self depth ~~ 1 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10629
		m := ImageMask width:width height:height.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10630
		m bits:(maskBits := ByteArray new:(m bytesPerRow * height)).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10631
		maskBits atAllPut:16rFF.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10632
		newImage mask:(m rotated:degrees)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10633
	    ]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10634
	]
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10635
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10636
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10637
    myDepth := self depth.
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10638
    myDepth == 1 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10639
	blackPixel := 0.
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10640
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10641
	maskedPixelsAre0 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10642
	    blackPixel := 0.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10643
	] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10644
	    blackPixel := self valueFromColor:Color black.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10645
	    blackPixel isNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10646
		blackPixel := self valueFromColor:Color white.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10647
		blackPixel isNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10648
		    blackPixel := 0.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10649
		]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10650
	    ]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10651
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10652
	self isMask ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10653
	    blackPixel := 0.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10654
	].
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10655
    ].
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10656
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10657
    newBits atAllPut:0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10658
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10659
    "/ now, walk over destination pixels,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10660
    "/ fetching from source.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10661
    "/ (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
 10662
    "/  in the destination image ...)
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10663
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10664
    halfW := (width - 1) / 2.0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10665
    halfH := (height - 1) / 2.0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10666
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10667
    bytesPerRow := self bytesPerRow.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10668
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10669
%{
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10670
    int __newHeight = __intVal(newHeight);
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10671
    int __newWidth = __intVal(newWidth);
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10672
    int __height = __intVal(__INST(height));
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10673
    int __width = __intVal(__INST(width));
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10674
    double __minX, __minY, __radians;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10675
    double __halfW, __halfH;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10676
    int __dstX, __dstY;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10677
    int __depth = __intVal(myDepth);
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10678
    unsigned char *__srcBytes, *__dstBytes;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10679
    unsigned char *__dstPtr, *__dstRowPtr, *__dstEndPtr;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10680
    int __nSrcBytes, __nDstBytes;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10681
    int __srcBytesPerRow = __intVal(bytesPerRow);
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10682
    int __dstBytesPerRow = __intVal(newBytesPerRow);
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10683
    int __dstMask, __blackPixel;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10684
    double __sin, __cos;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10685
    double sin(), cos();
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10686
#   define Float_PI 3.14159
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10687
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10688
    bad = true;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10689
    if (1
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10690
     && __isFloat(minX)
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10691
     && __isFloat(minY)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10692
     && __isFloat(radians)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10693
     && __isFloat(halfW)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10694
     && __isFloat(halfH)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10695
     && __isByteArray(newBits)
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
 10696
     && __isByteArrayLike(__INST(bytes))) {
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10697
	__srcBytes = __ByteArrayInstPtr(__INST(bytes))->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10698
	__dstBytes = __ByteArrayInstPtr(newBits)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10699
	__nSrcBytes = __byteArraySize(__INST(bytes));
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10700
	__nDstBytes = __byteArraySize(newBits);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10701
	__blackPixel = __intVal(blackPixel);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10702
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10703
	__radians = __floatVal(radians);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10704
	__radians = -__radians; /* sigh: clock-wise */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10705
	__sin = sin(__radians);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10706
	__cos = cos(__radians);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10707
	__minX = __floatVal(minX);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10708
	__minY = __floatVal(minY);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10709
	__halfW = __floatVal(halfW);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10710
	__halfH = __floatVal(halfH);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10711
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10712
	__dstRowPtr = __dstBytes;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10713
	__dstEndPtr = __dstBytes + __nDstBytes;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10714
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10715
#       define EARLY_OUT
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10716
#       define FAST_ADVANCE 5
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10717
#       define FAST_ADVANCE2
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10718
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10719
	switch (__depth) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10720
	    case 8:
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10721
		for (__dstY = 0; __dstY < __newHeight; __dstY++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10722
		    double __pY, __sinPY, __cosPY;
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 10723
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10724
		    int didFetchInRow = 0;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10725
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10726
		    __pY = (double)(__dstY + __minY);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10727
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10728
		    __sinPY = __sin * __pY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10729
		    __cosPY = __cos * __pY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10730
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10731
		    __dstPtr = __dstRowPtr;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10732
		    __dstRowPtr += __dstBytesPerRow;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10733
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10734
		    for (__dstX = 0; __dstX < __newWidth; __dstX++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10735
			double __pX, __nX;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10736
			unsigned __pix;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10737
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10738
			/* translate X in destination (center to 0/0) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10739
			__pX = (double)(__dstX + __minX);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10740
			/* rotate X */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10741
			__nX = (__cos * __pX) - __sinPY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10742
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10743
			/* translate X in source (origin to 0/0) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10744
			__nX = __nX + __halfW + 0.5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10745
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10746
			/* inside ? */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10747
			if (__nX < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10748
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10749
			    if (didFetchInRow) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10750
				break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10751
			    }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10752
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10753
#ifdef FAST_ADVANCE
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10754
			    if (__blackPixel == 0) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10755
				do {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10756
				    /* try advance by FAST_ADVANCE pixels ... */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10757
				    __dstX += FAST_ADVANCE; __dstPtr += FAST_ADVANCE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10758
				    if (__dstX >= __newWidth) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10759
					break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10760
				    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10761
				    __pX = (double)(__dstX + __minX);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10762
				    __nX = (__cos * __pX) - __sinPY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10763
				    __nX = __nX + __halfW + 0.5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10764
				} while (__nX < 0);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10765
				__dstX -= FAST_ADVANCE; __dstPtr -= FAST_ADVANCE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10766
			    }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10767
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10768
			    __pix = __blackPixel;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10769
			} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10770
			    int __srcX;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10771
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10772
			    __srcX = (int)__nX;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10773
			    /* inside ? */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10774
			    if (__srcX >= __width) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10775
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10776
				if (didFetchInRow) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10777
				    break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10778
				}
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 10779
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10780
#ifdef FAST_ADVANCE2
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10781
				if (__blackPixel == 0) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10782
				    do {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10783
					/* try advance by FAST_ADVANCE pixels ... */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10784
					__dstX += FAST_ADVANCE; __dstPtr += FAST_ADVANCE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10785
					if (__dstX >= __newWidth) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10786
					    break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10787
					}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10788
					__pX = (double)(__dstX + __minX);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10789
					__nX = (__cos * __pX) - __sinPY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10790
					__nX = __nX + __halfW + 0.5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10791
					__srcX = (int)__nX;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10792
				    } while (__srcX >= __width);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10793
				    __dstX -= FAST_ADVANCE; __dstPtr -= FAST_ADVANCE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10794
				}
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10795
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10796
				__pix = __blackPixel;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10797
			    } else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10798
				double __nY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10799
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10800
				/* rotate Y */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10801
				__nY = (__sin * __pX) + __cosPY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10802
				/* translate Y in source (origin to 0/0) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10803
				__nY = __nY + __halfH + 0.5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10804
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10805
				/* inside ? */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10806
				if (__nY < 0) {
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 10807
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10808
				    if (didFetchInRow) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10809
					break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10810
				    }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10811
#endif
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10812
#ifdef FAST_ADVANCE2
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10813
				    if (__blackPixel == 0) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10814
					do {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10815
					    /* try advance by FAST_ADVANCE pixels ... */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10816
					    __dstX += FAST_ADVANCE; __dstPtr += FAST_ADVANCE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10817
					    if (__dstX >= __newWidth) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10818
						break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10819
					    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10820
					    __pX = (double)(__dstX + __minX);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10821
					    __nY = (__sin * __pX) + __cosPY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10822
					    __nY = __nY + __halfH + 0.5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10823
					} while (__nY < 0);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10824
					__dstX -= FAST_ADVANCE; __dstPtr -= FAST_ADVANCE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10825
				    }
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 10826
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10827
				    __pix = __blackPixel;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10828
				} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10829
				    int __srcY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10830
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10831
				    __srcY = (int)__nY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10832
				    /* inside ? */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10833
				    if (__srcY >= __height) {
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 10834
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10835
					if (didFetchInRow) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10836
					    break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10837
					}
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10838
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10839
#ifdef FAST_ADVANCE
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10840
					if (__blackPixel == 0) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10841
					    do {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10842
						/* try advance by FAST_ADVANCE pixels ... */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10843
						__dstX += FAST_ADVANCE; __dstPtr += FAST_ADVANCE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10844
						if (__dstX >= __newWidth) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10845
						    break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10846
						}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10847
						__pX = (double)(__dstX + __minX);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10848
						__nY = (__sin * __pX) + __cosPY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10849
						__nY = __nY + __halfH + 0.5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10850
						__srcY = (int)__nY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10851
					    } while (__srcY >= __height);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10852
					    __dstX -= FAST_ADVANCE; __dstPtr -= FAST_ADVANCE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10853
					}
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10854
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10855
					__pix = __blackPixel;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10856
				    } else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10857
					/* fetch source pixel */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10858
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10859
					int idx;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10860
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10861
					didFetchInRow = 1;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10862
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10863
					idx = __srcY * __srcBytesPerRow + __srcX;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10864
					if ((unsigned)idx < __nSrcBytes) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10865
					    __pix = __srcBytes[idx];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10866
					} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10867
					    __pix = __blackPixel;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10868
					}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10869
				    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10870
				}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10871
			    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10872
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10873
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10874
			if (__pix != 0) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10875
			    *__dstPtr = __pix;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10876
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10877
			__dstPtr++;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10878
		    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10879
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10880
		break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10881
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10882
	    case 1:
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10883
		for (__dstY = 0; __dstY < __newHeight; __dstY++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10884
		    double __pY, __sinPY, __cosPY;
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 10885
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10886
		    int didFetchInRow = 0;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10887
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10888
		    __pY = (double)(__dstY + __minY);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10889
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10890
		    __sinPY = __sin * __pY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10891
		    __cosPY = __cos * __pY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10892
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10893
		    __dstPtr = __dstRowPtr;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10894
		    __dstMask = 0x80;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10895
		    __dstRowPtr += __dstBytesPerRow;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10896
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10897
		    for (__dstX = 0; __dstX < __newWidth; __dstX++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10898
			double __pX, __nX;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10899
			int __pix;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10900
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10901
			/* translate X in destination (center to 0/0) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10902
			__pX = (double)(__dstX + __minX);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10903
			/* rotate X */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10904
			__nX = (__cos * __pX) - __sinPY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10905
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10906
			/* translate X in source (origin to 0/0) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10907
			__nX = __nX + __halfW + 0.5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10908
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10909
			/* inside ? */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10910
			if (__nX < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10911
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10912
			    if (didFetchInRow) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10913
				break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10914
			    }
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 10915
#endif
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 10916
#ifdef FAST_ADVANCE
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10917
			    if (__blackPixel == 0) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10918
				do {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10919
				    /* try advance by 8 pixels ... */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10920
				    __dstX += 8; __dstPtr ++;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10921
				    if (__dstX >= __newWidth) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10922
					break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10923
				    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10924
				    __pX = (double)(__dstX + __minX);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10925
				    __nX = (__cos * __pX) - __sinPY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10926
				    __nX = __nX + __halfW + 0.5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10927
				} while (__nX < 0);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10928
				__dstX -= 8; __dstPtr--;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10929
			    }
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10930
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10931
			    __pix = __blackPixel;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10932
			} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10933
			    int __srcX;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10934
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10935
			    __srcX = (int)__nX;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10936
			    /* inside ? */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10937
			    if (__srcX >= __width) {
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10938
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10939
				if (didFetchInRow) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10940
				    break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10941
				}
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 10942
#endif
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 10943
#ifdef FAST_ADVANCE2
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10944
				if (__blackPixel == 0) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10945
				    do {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10946
					/* try advance by 8 pixels ... */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10947
					__dstX += 8; __dstPtr++;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10948
					if (__dstX >= __newWidth) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10949
					    break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10950
					}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10951
					__pX = (double)(__dstX + __minX);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10952
					__nX = (__cos * __pX) - __sinPY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10953
					__nX = __nX + __halfW + 0.5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10954
					__srcX = (int)__nX;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10955
				    } while (__srcX >= __width);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10956
				    __dstX -= 8; __dstPtr--;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10957
				}
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10958
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10959
				__pix = __blackPixel;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10960
			    } else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10961
				double __nY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10962
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10963
				/* rotate Y */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10964
				__nY = (__sin * __pX) + __cosPY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10965
				/* translate Y in source (origin to 0/0) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10966
				__nY = __nY + __halfH + 0.5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10967
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10968
				/* inside ? */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10969
				if (__nY < 0) {
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10970
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10971
				    if (didFetchInRow) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10972
					break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10973
				    }
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 10974
#endif
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 10975
#ifdef FAST_ADVANCE2
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10976
				    if (__blackPixel == 0) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10977
					do {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10978
					    /* try advance by 8 pixels ... */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10979
					    __dstX += 8; __dstPtr++;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10980
					    if (__dstX >= __newWidth) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10981
						break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10982
					    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10983
					    __pX = (double)(__dstX + __minX);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10984
					    __nY = (__sin * __pX) + __cosPY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10985
					    __nY = __nY + __halfH + 0.5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10986
					} while (__nY < 0);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10987
					__dstX -= 8; __dstPtr--;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10988
				    }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10989
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10990
				    __pix = __blackPixel;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10991
				} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10992
				    int __srcY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10993
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10994
				    __srcY = (int)__nY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10995
				    /* inside ? */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10996
				    if (__srcY >= __height) {
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 10997
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10998
					if (didFetchInRow) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10999
					    break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11000
					}
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 11001
#endif
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 11002
#ifdef FAST_ADVANCE
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11003
					if (__blackPixel == 0) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11004
					    do {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11005
						/* try advance by 8 pixels ... */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11006
						__dstX += 8; __dstPtr++;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11007
						if (__dstX >= __newWidth) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11008
						    break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11009
						}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11010
						__pX = (double)(__dstX + __minX);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11011
						__nY = (__sin * __pX) + __cosPY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11012
						__nY = __nY + __halfH + 0.5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11013
						__srcY = (int)__nY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11014
					    } while (__srcY >= __height);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11015
					    __dstX -= 8; __dstPtr--;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11016
					}
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11017
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11018
					__pix = __blackPixel;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11019
				    } else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11020
					/* fetch source pixel */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11021
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11022
					int idx, pV;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11023
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11024
					didFetchInRow = 1;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11025
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11026
					idx = __srcY * __srcBytesPerRow + (__srcX >> 3);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11027
					if ((unsigned)idx < __nSrcBytes) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11028
					    pV = __srcBytes[idx];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11029
					    __pix = (pV & (0x80 >> (__srcX & 7))) ? 1 : 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11030
					} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11031
					    __pix = __blackPixel;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11032
					}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11033
				    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11034
				}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11035
			    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11036
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11037
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11038
			/* store pixel */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11039
			if (__pix != 0) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11040
			    *__dstPtr |= __dstMask;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11041
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11042
			__dstMask >>= 1;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11043
			if (__dstMask == 0) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11044
			    __dstMask = 0x80;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11045
			    __dstPtr++;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11046
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11047
		    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11048
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11049
		break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11050
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11051
	    case 24:
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11052
		for (__dstY = 0; __dstY < __newHeight; __dstY++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11053
		    double __pY, __sinPY, __cosPY;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11054
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11055
		    int didFetchInRow = 0;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11056
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11057
		    __pY = (double)(__dstY + __minY);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11058
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11059
		    __sinPY = __sin * __pY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11060
		    __cosPY = __cos * __pY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11061
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11062
		    __dstPtr = __dstRowPtr;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11063
		    __dstRowPtr += __dstBytesPerRow;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11064
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11065
		    for (__dstX = 0; __dstX < __newWidth; __dstX++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11066
			double __pX, __nX;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11067
			unsigned __pix;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11068
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11069
			/* translate X in destination (center to 0/0) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11070
			__pX = (double)(__dstX + __minX);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11071
			/* rotate X */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11072
			__nX = (__cos * __pX) - __sinPY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11073
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11074
			/* translate X in source (origin to 0/0) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11075
			__nX = __nX + __halfW + 0.5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11076
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11077
			/* inside ? */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11078
			if (__nX < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11079
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11080
			    if (didFetchInRow) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11081
				break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11082
			    }
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 11083
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11084
			    __pix = __blackPixel;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11085
			} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11086
			    int __srcX;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11087
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11088
			    __srcX = (int)__nX;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11089
			    /* inside ? */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11090
			    if (__srcX >= __width) {
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11091
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11092
				if (didFetchInRow) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11093
				    break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11094
				}
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11095
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11096
				__pix = __blackPixel;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11097
			    } else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11098
				double __nY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11099
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11100
				/* rotate Y */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11101
				__nY = (__sin * __pX) + __cosPY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11102
				/* translate Y in source (origin to 0/0) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11103
				__nY = __nY + __halfH + 0.5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11104
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11105
				/* inside ? */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11106
				if (__nY < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11107
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11108
				    if (didFetchInRow) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11109
					break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11110
				    }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11111
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11112
				    __pix = __blackPixel;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11113
				} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11114
				    int __srcY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11115
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11116
				    __srcY = (int)__nY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11117
				    /* inside ? */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11118
				    if (__srcY >= __height) {
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11119
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11120
					if (didFetchInRow) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11121
					    break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11122
					}
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11123
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11124
					__pix = __blackPixel;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11125
				    } else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11126
					/* fetch source pixel */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11127
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11128
					int idx;
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11129
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11130
					didFetchInRow = 1;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11131
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11132
					idx = __srcY * __srcBytesPerRow + __srcX + __srcX + __srcX;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11133
					if ((unsigned)idx < __nSrcBytes) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11134
					    __pix = __srcBytes[idx];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11135
					    __pix = (__pix<<8) | __srcBytes[idx+1];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11136
					    __pix = (__pix<<8) | __srcBytes[idx+2];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11137
					} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11138
					    __pix = __blackPixel;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11139
					}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11140
				    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11141
				}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11142
			    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11143
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11144
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11145
			/* store pixel */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11146
			if (__pix != 0) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11147
			    __dstPtr[0] = (__pix >> 16 & 0xFF);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11148
			    __dstPtr[1] = (__pix >> 8) & 0xFF;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11149
			    __dstPtr[2] = __pix & 0xFF;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11150
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11151
			__dstPtr += 3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11152
		    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11153
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11154
		break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11155
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11156
	    default:
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11157
		for (__dstY = 0; __dstY < __newHeight; __dstY++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11158
		    double __pY, __sinPY, __cosPY;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11159
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11160
		    int didFetchInRow = 0;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11161
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11162
		    __pY = (double)(__dstY + __minY);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11163
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11164
		    __sinPY = __sin * __pY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11165
		    __cosPY = __cos * __pY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11166
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11167
		    __dstPtr = __dstRowPtr;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11168
		    __dstMask = 0x80;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11169
		    __dstRowPtr += __dstBytesPerRow;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11170
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11171
		    for (__dstX = 0; __dstX < __newWidth; __dstX++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11172
			double __pX, __nX;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11173
			OBJ __pix;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11174
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11175
			/* translate X in destination (center to 0/0) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11176
			__pX = (double)(__dstX + __minX);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11177
			/* rotate X */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11178
			__nX = (__cos * __pX) - __sinPY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11179
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11180
			/* translate X in source (origin to 0/0) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11181
			__nX = __nX + __halfW + 0.5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11182
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11183
			/* inside ? */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11184
			if (__nX < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11185
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11186
			    if (didFetchInRow) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11187
				break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11188
			    }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11189
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11190
			    __pix = blackPixel;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11191
			} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11192
			    int __srcX;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11193
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11194
			    __srcX = (int)__nX;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11195
			    /* inside ? */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11196
			    if (__srcX >= __width) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11197
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11198
				if (didFetchInRow) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11199
				    break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11200
				}
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11201
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11202
				__pix = blackPixel;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11203
			    } else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11204
				double __nY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11205
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11206
				/* rotate Y */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11207
				__nY = (__sin * __pX) + __cosPY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11208
				/* translate Y in source (origin to 0/0) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11209
				__nY = __nY + __halfH + 0.5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11210
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11211
				/* inside ? */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11212
				if (__nY < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11213
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11214
				    if (didFetchInRow) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11215
					break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11216
				    }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11217
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11218
				    __pix = blackPixel;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11219
				} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11220
				    int __srcY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11221
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11222
				    __srcY = (int)__nY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11223
				    /* inside ? */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11224
				    if (__srcY >= __height) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11225
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11226
					if (didFetchInRow) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11227
					    break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11228
					}
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11229
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11230
					__pix = blackPixel;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11231
				    } else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11232
					/* fetch source pixel */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11233
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11234
					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
 11235
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11236
					didFetchInRow = 1;
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11237
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11238
					__pix = (*valAt.ilc_func)(self,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11239
							      @symbol(pixelAtX:y:),
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11240
							      nil, &valAt,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11241
							      __MKSMALLINT(__srcX),
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11242
							      __MKSMALLINT(__srcY));
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11243
				    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11244
				}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11245
			    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11246
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11247
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11248
			/* store pixel */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11249
			{
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11250
			    static struct inlineCache atPutVal = _ILC3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11251
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11252
			    if (__pix != __MKSMALLINT(0)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11253
				(*atPutVal.ilc_func)(newImage,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11254
						      @symbol(pixelAtX:y:put:),
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11255
						      nil, &atPutVal,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11256
						      __MKSMALLINT(__dstX),
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11257
						      __MKSMALLINT(__dstY),
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11258
						      __pix
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11259
						     );
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11260
			    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11261
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11262
		    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11263
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11264
		break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11265
	}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11266
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11267
	bad = false;
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11268
    }
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11269
%}.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11270
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11271
    bad ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11272
	"/ should not happen
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11273
	self primitiveFailed
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11274
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11275
"/        sinRot := radians negated sin.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11276
"/        cosRot := radians negated cos.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11277
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11278
"/        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
 11279
"/            pY := (dstY + minY).
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11280
"/            sinPY := (sinRot * pY).
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11281
"/            cosPY := (cosRot * pY).
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11282
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11283
"/            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
 11284
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11285
"/                "/ translate center to origin
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11286
"/                pX := (dstX + minX).
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11287
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11288
"/                nX := (cosRot * pX) - sinPY.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11289
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11290
"/                "/ translate in source
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11291
"/                srcX := nX + halfW.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11292
"/                srcX := srcX rounded.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11293
"/                "/ inside ?
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11294
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11295
"/                (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
 11296
"/                    nY := (sinRot * pX) + cosPY.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11297
"/                    srcY := nY + halfH.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11298
"/                    srcY := srcY rounded.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11299
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11300
"/                    "/ inside ?
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11301
"/                    (srcY >= 0 and:[srcY < height]) ifTrue:[
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 11302
"/                        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
 11303
"/                    ] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11304
"/                        pix := blackPixel.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11305
"/                    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11306
"/                ] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11307
"/                    pix := blackPixel.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11308
"/                ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11309
"/                pix ~~ blackPixel ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11310
"/                    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
 11311
"/                ]
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11312
"/            ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11313
"/        ].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11314
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11315
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11316
    ^ newImage
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11317
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11318
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11319
     |i|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11320
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 11321
     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
 11322
     i inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11323
     (i rotated:45) inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11324
     (i rotated:90) inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11325
     (i rotated:91) inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11326
     (i rotated:95) inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11327
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11328
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11329
     |i|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11330
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 11331
     i := Smalltalk imageFromFileNamed:'bitmaps/gifImages/garfield.gif' inPackage:'stx:goodies'.
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 11332
     i := Depth24Image fromImage:i.
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 11333
     (i rotated:200) inspect
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11334
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11335
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11336
     |i|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11337
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 11338
     i := Smalltalk imageFromFileNamed:'bitmaps/gifImages/garfield.gif' inPackage:'stx:goodies'.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11339
     Transcript showCR:(
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11340
	Time millisecondsToRun:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11341
	   i rotated:45.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11342
	]
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11343
     ).
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11344
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11345
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11346
     |v i rI rot|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11347
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 11348
     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
 11349
     v := View new extent:(i width max:100)@(i height max:100).
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11350
     v openAndWait.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11351
     rot := 0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11352
     [true] whileTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11353
	rI := i rotated:rot.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11354
	rI := rI onDevice:v device.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11355
	v clear.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11356
	v displayForm:rI x:(v width-rI width)//2 y:(v height-rI height)//2.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11357
	rot := rot + 5.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11358
	rI close.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11359
     ]
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11360
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11361
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11362
     |v i rI rot|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11363
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 11364
     i := Smalltalk imageFromFileNamed:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies'.
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 11365
     v := View new extent:400@400.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11366
     v openAndWait.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11367
     rot := 0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11368
     [true] whileTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11369
	rI := i rotated:rot.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11370
	rI := rI onDevice:v device.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11371
	v clear.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11372
	v displayForm:rI x:(v width-rI width)//2 y:(v height-rI height)//2.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11373
	rot := rot + 5.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11374
	rI close.
4952
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11375
     ]
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11376
    "
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11377
    "
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11378
     |v i rI rot|
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11379
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11380
     i := Form width:200 height:100 onDevice:Screen current.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11381
     i clear.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11382
     i displayLineFrom:(0@0) to:(199@0).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11383
     i displayLineFrom:(199@0) to:(199@99).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11384
     i displayLineFrom:(199@99) to:(0@99).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11385
     i displayLineFrom:(0@99) to:(0@0).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11386
     i displayLineFrom:(0@0) to:(199@100).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11387
     i displayLineFrom:(199@0) to:(0@100).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11388
     i := Image fromForm:i.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11389
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11390
     v := View new extent:400@400.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11391
     v openAndWait.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11392
     rot := 0.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11393
     [true] whileTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11394
	rI := i rotated:rot.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11395
	rI := rI onDevice:v device.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11396
	v clear.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11397
	v displayForm:rI x:(v width-rI width)//2 y:(v height-rI height)//2.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11398
	rot := rot + 5.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11399
	rI close.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11400
	Delay waitForSeconds:0.1.
4952
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11401
     ]
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11402
    "
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11403
    "
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11404
     |v i rI rot|
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11405
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11406
     i := Form width:200 height:100 onDevice:Screen current.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11407
     i clear.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11408
     i displayLineFrom:(0@0) to:(199@0).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11409
     i displayLineFrom:(199@0) to:(199@99).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11410
     i displayLineFrom:(199@99) to:(0@99).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11411
     i displayLineFrom:(0@99) to:(0@0).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11412
     i displayLineFrom:(0@0) to:(199@100).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11413
     i displayLineFrom:(199@0) to:(0@100).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11414
     i := Image fromForm:i.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11415
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11416
     v := View new extent:400@400.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11417
     v openAndWait.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11418
     rot := 0.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11419
     [true] whileTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11420
	rI := i rotated:rot.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11421
	rI := rI onDevice:v device.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11422
	v clear.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11423
	v displayForm:rI x:(v width-rI width)//2 y:(v height-rI height)//2.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11424
	rot := rot + 30.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11425
	rI close.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11426
	Delay waitForSeconds:0.3.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11427
     ]
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11428
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11429
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11430
    "Modified: 22.4.1997 / 17:36:37 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 11431
!
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 11432
54
29a6b2f8e042 *** empty log message ***
claus
parents: 46
diff changeset
 11433
lightened
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 11434
    "return a new image which is slightly brighter than the receiver.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 11435
     The receiver must be a palette image (currently).
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11436
     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
 11437
     CAVEAT: Need an argument, which specifies by how much it should be lighter."
54
29a6b2f8e042 *** empty log message ***
claus
parents: 46
diff changeset
 11438
5655
37bd5c7eb765 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 5643
diff changeset
 11439
    ^ self copyWithColorMapProcessing:[:clr | clr lightened]
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11440
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11441
    "
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11442
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11443
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') lightened inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11444
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') darkened inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11445
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') darkened darkened inspect
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11446
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11447
5655
37bd5c7eb765 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 5643
diff changeset
 11448
    "Modified: / 24-11-2010 / 11:17:55 / cg"
54
29a6b2f8e042 *** empty log message ***
claus
parents: 46
diff changeset
 11449
!
29a6b2f8e042 *** empty log message ***
claus
parents: 46
diff changeset
 11450
134
claus
parents: 132
diff changeset
 11451
magnifiedBy:scale
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 11452
    "return a new image magnified by scalePoint, aPoint.
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
 11453
     If non-integral magnify is asked for, pass the work on to 'hardMagnifyBy:'
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
 11454
     while simple (integral) magnifications are handled here."
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11455
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 11456
    |scalePoint mX mY
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11457
     magX      "{ Class: SmallInteger }"   "new version of stc can find this out itself..."
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11458
     magY      "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11459
     srcOffset "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11460
     dstOffset "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11461
     w         "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11462
     h         "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11463
     first
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 11464
     newWidth newHeight newImage newBits newMask
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 11465
     bitsPerPixel newBytesPerRow oldBytesPerRow
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 11466
     bytes|
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11467
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 11468
    scalePoint := scale asPoint.
2772
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
 11469
    mX := scalePoint x.
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
 11470
    mY := scalePoint y.
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11471
    ((mX <= 0) or:[mY <= 0]) ifTrue:[^ nil].
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11472
    ((mX = 1) and:[mY = 1]) ifTrue:[^ self].
48194c26a46c Initial revision
claus
parents:
diff changeset
 11473
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11474
    ((mX isMemberOf:SmallInteger) and:[mY isMemberOf:SmallInteger]) ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11475
	^ self hardMagnifiedBy:scalePoint
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 11476
    ].
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 11477
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 11478
    bytes := self bits.
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
 11479
    bitsPerPixel := self depth.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11480
    oldBytesPerRow := ((width * bitsPerPixel) + 7) // 8.
48194c26a46c Initial revision
claus
parents:
diff changeset
 11481
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11482
    w := width.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11483
    h := height.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11484
    magX := mX.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11485
    magY := mY.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11486
2772
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
 11487
    newWidth := w * magX.
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
 11488
    newHeight := h * magY.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11489
    newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8.
48194c26a46c Initial revision
claus
parents:
diff changeset
 11490
    newBits := ByteArray uninitializedNew:(newBytesPerRow * newHeight).
48194c26a46c Initial revision
claus
parents:
diff changeset
 11491
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 11492
    mask notNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11493
	newMask := (mask magnifiedBy:scalePoint)
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 11494
    ].
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 11495
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11496
    newImage := self species new.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11497
    newImage
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11498
	width:newWidth
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11499
	height:newHeight
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11500
	photometric:photometric
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11501
	samplesPerPixel:samplesPerPixel
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11502
	bitsPerSample:bitsPerSample
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11503
	colorMap:colorMap copy
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11504
	bits:newBits
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11505
	mask:newMask.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11506
48194c26a46c Initial revision
claus
parents:
diff changeset
 11507
    mX = 1 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11508
	"expand rows only"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11509
	srcOffset := 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11510
	dstOffset := 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11511
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11512
	1 to:h do:[:row |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11513
	    1 to:magY do:[:i |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11514
		newBits replaceFrom:dstOffset
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11515
			to:(dstOffset + oldBytesPerRow - 1)
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11516
			with:bytes
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11517
			startingAt:srcOffset.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11518
		dstOffset := dstOffset + newBytesPerRow
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11519
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11520
	    srcOffset := srcOffset + oldBytesPerRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11521
	].
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11522
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11523
	"expand cols"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11524
	(mX > 1) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11525
	    dstOffset := 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11526
	    srcOffset := 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11527
	    1 to:h do:[:row |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11528
		self magnifyRowFrom:bytes
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11529
		     offset:srcOffset
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11530
		     into:newBits
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11531
		     offset:dstOffset
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11532
		     factor:mX.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11533
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11534
		first := dstOffset.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11535
		dstOffset := dstOffset + newBytesPerRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11536
		" and copy for row expansion "
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11537
		2 to:magY do:[:i |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11538
		    newBits replaceFrom:dstOffset
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11539
			    to:(dstOffset + newBytesPerRow - 1)
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11540
			    with:newBits
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11541
			    startingAt:first.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11542
		    dstOffset := dstOffset + newBytesPerRow
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11543
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11544
		srcOffset := srcOffset + oldBytesPerRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11545
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11546
	]
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11547
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
 11548
    ^ newImage
48194c26a46c Initial revision
claus
parents:
diff changeset
 11549
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11550
    "
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11551
     ((Image fromFile:'goodies/bitmaps/gifImages/claus.gif') magnifiedBy:1@2)
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11552
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11553
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11554
    "Modified: 24.4.1997 / 18:32:04 / cg"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
 11555
!
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
 11556
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11557
magnifiedPreservingRatioTo:anExtent
154
claus
parents: 153
diff changeset
 11558
    "return a new image magnified to fit into anExtent,
claus
parents: 153
diff changeset
 11559
     preserving the receivers width/height ratio.
claus
parents: 153
diff changeset
 11560
     (i.e. not distorting the image).
claus
parents: 153
diff changeset
 11561
     See also #magnifiedTo: and #magnifiedBy:"
claus
parents: 153
diff changeset
 11562
claus
parents: 153
diff changeset
 11563
    |rX rY|
claus
parents: 153
diff changeset
 11564
claus
parents: 153
diff changeset
 11565
    rX := anExtent x / self width.
claus
parents: 153
diff changeset
 11566
    rY := anExtent y / self height.
claus
parents: 153
diff changeset
 11567
    ^ self magnifiedBy:(rX min:rY)
claus
parents: 153
diff changeset
 11568
claus
parents: 153
diff changeset
 11569
    "
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11570
     ((Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') magnifiedPreservingRatioTo:100@100)
154
claus
parents: 153
diff changeset
 11571
claus
parents: 153
diff changeset
 11572
    in contrast to:
claus
parents: 153
diff changeset
 11573
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11574
     ((Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') magnifiedTo:100@100)
1630
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 11575
    "
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 11576
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 11577
    "Modified: 22.4.1997 / 12:33:46 / cg"
154
claus
parents: 153
diff changeset
 11578
!
claus
parents: 153
diff changeset
 11579
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11580
magnifiedTo:anExtent
154
claus
parents: 153
diff changeset
 11581
    "return a new image magnified to have the size specified by extent.
claus
parents: 153
diff changeset
 11582
     This may distort the image if the arguments ratio is not the images ratio.
claus
parents: 153
diff changeset
 11583
     See also #magnifiedPreservingRatioTo: and #magnifiedBy:"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 11584
134
claus
parents: 132
diff changeset
 11585
    ^ self magnifiedBy:(anExtent / self extent)
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 11586
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 11587
    "
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 11588
     ((Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') magnifiedTo:100@100)
154
claus
parents: 153
diff changeset
 11589
claus
parents: 153
diff changeset
 11590
    in contrast to:
claus
parents: 153
diff changeset
 11591
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 11592
     ((Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') magnifiedPreservingRatioTo:100@100)
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 11593
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 11594
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 11595
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11596
mixed:amount with:aColor
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11597
    "return a new image which is blended with some color;
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11598
     amount determines how much of the blending color is applied (0..)
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11599
     where 0 means: blending color pure.
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11600
     The receiver must be a palette image (currently).
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11601
     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
 11602
     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
 11603
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11604
     ^ self
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11605
	copyWithColorMapProcessing:[:clr | clr mixed:amount with:aColor]
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11606
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11607
    "
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11608
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11609
     ((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
 11610
     ((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
 11611
     ((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
 11612
     ((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
 11613
     ((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
 11614
     ((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
 11615
     ((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
 11616
    "
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11617
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11618
    "Modified: 24.4.1997 / 18:31:23 / cg"
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11619
!
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11620
1762
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11621
negative
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11622
    "return a new image which is a negative of the receiver.
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11623
     The receiver must be a palette image (currently)."
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11624
1763
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 11625
    |newImage|
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 11626
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 11627
    colorMap isNil ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11628
	photometric == #blackIs0 ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11629
	    newImage := self copy.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11630
	    newImage photometric:#whiteIs0.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11631
	    ^ newImage
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11632
	].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11633
	photometric == #whiteIs0 ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11634
	    newImage := self copy.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11635
	    newImage photometric:#blackIs0.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11636
	    ^ newImage
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11637
	].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11638
	^ nil
1763
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 11639
    ].
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 11640
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11641
     ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11642
	copyWithColorMapProcessing:[:clr |
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11643
		|newColor|
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11644
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11645
		newColor := Color
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11646
				redByte:(255 - clr redByte)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11647
				greenByte:(255 - clr greenByte)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11648
				blueByte:(255 - clr blueByte)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11649
	]
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11650
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11651
    "
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11652
     (Image fromFile:'goodies/bitmaps/gifImages/claus.gif') inspect
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11653
     (Image fromFile:'goodies/bitmaps/gifImages/claus.gif') negative inspect
1762
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11654
    "
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11655
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11656
    "Created: 20.6.1997 / 13:13:41 / cg"
1763
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 11657
    "Modified: 20.6.1997 / 13:17:50 / cg"
1762
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11658
!
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11659
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11660
rotated:degrees
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11661
    "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
 11662
     degrees clockwise.
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11663
     Notice, that the resulting image has a different extent.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11664
     If rotation is heavily used, the workHorse methods
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11665
     (#easyRotateBitsInto:angle: and #hardRotateBitsInto:angle) may
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11666
     be redefined in concrete image subclasses."
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11667
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 11668
    |nW nH newImage d|
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11669
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11670
    d := degrees.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11671
    [d < 0] whileTrue:[d := d + 360].
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11672
    d >= 360 ifTrue:[d := d \\ 360].
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11673
    d := d truncated.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11674
    d = 0 ifTrue:[^ self].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11675
    ((d ~= 90) and:[(d ~= 270) and:[d ~= 180]]) ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11676
	^ self hardRotated:d
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11677
    ].
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11678
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11679
    d = 180 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11680
	nW := width.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11681
	nH := height.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11682
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11683
	nW := height.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11684
	nH := width.
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11685
    ].
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11686
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11687
    newImage := self species new.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11688
    newImage width:nW.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11689
    newImage height:nH.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 11690
    newImage createPixelStore.
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11691
    newImage photometric:photometric.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11692
    newImage samplesPerPixel:samplesPerPixel.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11693
    newImage bitsPerSample:bitsPerSample.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11694
    newImage colorMap:colorMap copy.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11695
    mask notNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11696
	newImage mask:(mask rotated:degrees)
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11697
    ].
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11698
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11699
    self easyRotateBitsInto:newImage angle:d.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11700
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11701
    ^ newImage
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 11702
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11703
    "
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11704
     |i|
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11705
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11706
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11707
     i inspect.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11708
     (i rotated:45) inspect.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11709
     (i rotated:90) inspect.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11710
     (i rotated:180) inspect.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11711
     (i rotated:270) inspect.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11712
    "
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11713
    "
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11714
     |i|
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11715
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11716
     i := Image fromFile:'goodies/bitmaps/xpmBitmaps/misc_icons/BOOK.xpm'.
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11717
     i inspect.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11718
     (i rotated:90) inspect.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11719
     (i rotated:180) inspect.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11720
     (i rotated:270) inspect.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11721
    "
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11722
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11723
    "Modified: 24.4.1997 / 18:33:42 / cg"
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11724
!
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11725
6624
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11726
slightlyDarkened
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11727
    "return a new image which is slightly darker than the receiver.
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11728
     The receiver must be a palette image (currently).
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11729
     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
 11730
     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
 11731
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11732
    ^ self copyWithColorMapProcessing:[:clr | clr slightlyDarkened]
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11733
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11734
    "
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11735
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') inspect
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11736
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') lightened inspect
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11737
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') darkened inspect
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11738
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') darkened darkened inspect
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11739
    "
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11740
!
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11741
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11742
slightlyLightened
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11743
    "return a new image which is slightly brighter than the receiver.
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11744
     The receiver must be a palette image (currently).
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11745
     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
 11746
     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
 11747
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11748
    ^ self copyWithColorMapProcessing:[:clr | clr slightlyLightened]
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11749
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11750
    "
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11751
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') inspect
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11752
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') lightened inspect
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11753
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') darkened inspect
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11754
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') darkened darkened inspect
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11755
    "
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11756
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11757
    "Modified: / 24-11-2010 / 11:17:55 / cg"
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11758
!
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11759
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11760
threeDProjected:fraction1 and:fraction2
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11761
    "return a 3D-projected version"
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11762
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11763
    |dx1 dx2 newImage newBytesPerRow newBits
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11764
     blackPixel halfW halfH m myDepth maskBits pix fr fl ml mr dm fractX my fy dstY o1 o2 df|
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11765
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11766
    newImage := self species new.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11767
    newImage width:width.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11768
    newImage height:height.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11769
    newBytesPerRow := newImage bytesPerRow.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11770
    newImage createPixelStore.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11771
    newBits := newImage bits.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11772
    newImage photometric:photometric.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11773
    newImage samplesPerPixel:samplesPerPixel.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11774
    newImage bitsPerSample:bitsPerSample.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11775
    newImage colorMap:colorMap copy.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11776
    newImage maskedPixelsAre0:maskedPixelsAre0.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11777
    mask notNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11778
	newImage mask:(mask threeDProjected:fraction1 and:fraction2)
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11779
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11780
	self isMask ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11781
	    self depth ~~ 1 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11782
		m := ImageMask width:width height:height.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11783
		m bits:(maskBits := ByteArray new:(m bytesPerRow * height)).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11784
		maskBits atAllPut:16rFF.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11785
		newImage mask:(m threeDProjected:fraction1 and:fraction2)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11786
	    ]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11787
	]
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11788
    ].
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11789
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11790
    myDepth := self depth.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11791
    myDepth == 1 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11792
	blackPixel := 0.
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11793
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11794
	maskedPixelsAre0 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11795
	    blackPixel := 0.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11796
	] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11797
	    blackPixel := self valueFromColor:Color black.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11798
	    blackPixel isNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11799
		blackPixel := self valueFromColor:Color white.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11800
		blackPixel isNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11801
		    blackPixel := 0.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11802
		]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11803
	    ]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11804
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11805
	self isMask ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11806
	    blackPixel := 0.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11807
	].
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11808
    ].
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11809
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11810
    newBits atAllPut:0.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11811
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11812
    "/ now, walk over destination pixels,
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11813
    "/ fetching from source.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11814
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11815
    halfW := (width - 1) / 2.0.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11816
    halfH := (height - 1) / 2.0.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11817
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11818
    "/  --------------------------------------------------------------
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11819
    "/  |**************                                              |
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11820
    "/  |              ************                                  | dx1
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11821
    "/  |                          *************                     |
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11822
    "/  |                                       **********           |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11823
    "/  |fl                          fy                   ***********|
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11824
    "/  |                                                            | fr
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11825
    "/  |                                                            | Mr  (!!= Ml)      |
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11826
    "/  |Ml                          my                              | fr               | dm (=Mr-Ml)
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11827
    "/  |                                                     *******|                  |
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11828
    "/  |                            fy              *********       |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11829
    "/  |fl                                 *********                |
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11830
    "/  |                          *********                         | dx2
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11831
    "/  |                 *********                                  |
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11832
    "/  |        *********                                           |
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11833
    "/  |********                                                    |
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11834
    "/  --------------------------------------------------------------
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11835
    dx1 := height * fraction1.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11836
    dx2 := height * fraction2.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11837
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11838
    fr := (height - dx1 - dx2) / 2.0.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11839
    fl := (height) / 2.0.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11840
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11841
    ml := height / 2.0.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11842
    mr := dx1+fr.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11843
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11844
    dm := mr-ml.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11845
    df := fr-fl.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11846
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11847
    0 to:width-1 do:[:srcX |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11848
	fractX := srcX / width.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11849
	my := ml + (dm * fractX).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11850
	fy := fl + (df * fractX).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11851
	o1 := dx1 * fractX.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11852
	o2 := dx2 * fractX.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11853
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11854
	0 to:height-1 do:[:srcY |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11855
	    srcY < halfH ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11856
		dstY := o1 + (fy * (srcY / halfH)).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11857
	    ] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11858
		dstY := my + (fy * ((srcY-halfH) / halfH)).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11859
	    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11860
	    pix := self pixelAtX:srcX y:srcY.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11861
	    dstY < 0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11862
		ifTrue:[dstY := 0]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11863
		ifFalse:[ dstY >= height ifTrue:[dstY := height-1]].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11864
	    newImage pixelAtX:srcX y:dstY truncated put:pix.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11865
	].
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11866
    ].
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11867
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11868
    ^ newImage
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11869
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11870
    "
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11871
     |i|
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11872
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11873
     i := Smalltalk imageFromFileNamed:'bitmaps/gifImages/garfield.gif' inPackage:'stx:goodies'.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11874
     i := Depth24Image fromImage:i.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11875
     (i threeDProjected:0.1 and:0.3) inspect
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11876
     (i threeDProjected:0.1 and:0.1) inspect
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11877
    "
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11878
!
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11879
3905
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11880
withColorResolutionReducedBy:numBits
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11881
    "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
 11882
     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
 11883
     If anything fails, return nil."
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11884
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11885
    |xMax 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
 11886
     newColors newColorArray newImage extMask extBits newPixelValue|
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11887
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11888
    numBits > 7 ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11889
	^ nil
3905
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11890
    ].
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11891
    mask := (16rFF bitShift:numBits) bitAnd:16rFF.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11892
    extMask := (1 bitShift:numBits).
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11893
    extBits := extMask - 1.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11894
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11895
    anyChange := false.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11896
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11897
    newColors := Set new.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11898
    newColorArray := OrderedCollection new.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11899
    map := Array new:256.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11900
    revMap := OrderedCollection new.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11901
4317
a24172a52a76 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4296
diff changeset
 11902
    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
 11903
    newImage photometric:photometric.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11904
    newImage colorMap:(self colorMap copy).
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11905
    newImage bits:(self bits copy).
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11906
    newImage mask:(self mask copy).
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11907
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11908
    xMax := width - 1.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11909
    yMax := height - 1.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11910
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11911
    newPixelValue :=
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11912
	[:image :pixelValue |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11913
	    |r g b nR nG nB|
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11914
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11915
	    r := image redBitsOf:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11916
	    g := image greenBitsOf:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11917
	    b := image blueBitsOf:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11918
	    nR := r bitAnd:mask. (nR bitAnd:extMask)~~0 ifTrue:[nR := nR bitOr:extBits].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11919
	    nG := g bitAnd:mask. (nG bitAnd:extMask)~~0 ifTrue:[nG := nG bitOr:extBits].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11920
	    nB := b bitAnd:mask. (nB bitAnd:extMask)~~0 ifTrue:[nB := nB bitOr:extBits].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11921
	    image valueFromRedBits:nR greenBits:nG blueBits:nB.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11922
	].
3905
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11923
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11924
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11925
    photometric == #palette ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11926
	"/ direct manipulation of the pixels
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11927
	0 to:yMax do:[:y |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11928
	    0 to:xMax do:[:x |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11929
		pix := self pixelAtX:x y:y.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11930
		n_pix := newPixelValue value:self value:pix.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11931
		n_pix ~= pix ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11932
		    newImage pixelAtX:x y:y put:n_pix.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11933
		    anyChange := true.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11934
		]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11935
	    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11936
	].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11937
	anyChange ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11938
	    ^ nil
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11939
	].
3905
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11940
    ] ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11941
	"/ manipulate the colormap
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11942
	0 to:yMax do:[:y |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11943
	    0 to:xMax do:[:x |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11944
		pix := self pixelAtX:x y:y.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11945
		(n_pix := map at:pix+1) isNil ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11946
		    clr := self colorAtX:x y:y.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11947
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11948
		    r := clr redByte.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11949
		    g := clr greenByte.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11950
		    b := clr blueByte.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11951
		    nR := r bitAnd:mask. (nR bitAnd:extMask)~~0 ifTrue:[nR := nR bitOr:extBits].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11952
		    nG := g bitAnd:mask. (nR bitAnd:extMask)~~0 ifTrue:[nR := nR bitOr:extBits].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11953
		    nB := b bitAnd:mask. (nR bitAnd:extMask)~~0 ifTrue:[nR := nR bitOr:extBits].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11954
		    n_clr := Color redByte:nR greenByte:nG blueByte:nB.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11955
		    (newColors includes:n_clr) ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11956
			newColors add:n_clr.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11957
			newColorArray add:n_clr.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11958
			revMap add:pix.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11959
			map at:pix+1 put:(n_pix := revMap size - 1).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11960
		    ] ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11961
			"/ mhmh - multiple pixels mapped to the same color
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11962
			n_pix := (newColorArray indexOf:n_clr) - 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11963
			map at:pix+1 put:n_pix.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11964
		    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11965
		].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11966
		newImage pixelAtX:x y:y put:n_pix.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11967
	    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11968
	].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11969
	revMap size == self colorMap size ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11970
	    revMap = (0 to:revMap size-1) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11971
		^ nil
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11972
	    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11973
	].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11974
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11975
	newImage colorMap:(MappedPalette withColors:newColorArray).
3905
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11976
    ].
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11977
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11978
    ^ newImage
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11979
!
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11980
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11981
withPixelFunctionApplied:pixelFunctionBlock
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11982
    "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
 11983
     on the pixel colors.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11984
     Notice: this method is very slow - either apply pixel values
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11985
     (#withPixelFunctionAppliedToPixels:) or redefine this method in
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11986
     a concrete subclass.
3860
571f1cd259f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3855
diff changeset
 11987
     (read `Beyond photography, by Gerard J. Holzmann;
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11988
	   ISBM 0-13-074410-7)
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11989
     See blurred / oilPointed as examples ...)"
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11990
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11991
    |w  "{Class: SmallInteger }"
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11992
     h  "{Class: SmallInteger }"
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 11993
     newImage "newBits newBytesPerRow"|
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11994
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11995
    newImage := self species new.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 11996
    newImage depth:self depth.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11997
    newImage width:width.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11998
    newImage height:height.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 11999
"/    newBytesPerRow := ((width * self depth) + 7) // 8.
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12000
"/    newBits := ByteArray uninitializedNew:(newBytesPerRow * height).
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12001
    newImage createPixelStore. "/ bits:newBits.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12002
    newImage photometric:photometric.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12003
    newImage samplesPerPixel:samplesPerPixel.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12004
    newImage bitsPerSample:bitsPerSample.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12005
    newImage colorMap:colorMap copy.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12006
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12007
    w := width - 1.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12008
    h := height - 1.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12009
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12010
    0 to:h do:[:y |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12011
	0 to:w do:[:x |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12012
	    newImage colorAtX:x y:y put:(pixelFunctionBlock
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12013
						value:self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12014
						value:(self colorAtX:x y:y)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12015
						value:x
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12016
						value:y)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12017
	]
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12018
    ].
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12019
    ^ newImage
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12020
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12021
    "black out everything except for some rectangle:
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12022
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 12023
     |i black|
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12024
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12025
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12026
     i inspect.
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 12027
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 12028
     black := Color black.
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 12029
     (i withPixelFunctionApplied:[:oldImage :oldColor :x :y |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12030
			((x between:100 and:200)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12031
			and:[y between:100 and:200]) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12032
			    oldColor
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12033
			] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12034
			    black.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12035
			]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12036
		     ]) inspect.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12037
    "
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12038
    "brighten a frame:
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12039
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12040
     |i black w h|
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12041
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12042
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12043
     i inspect.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12044
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12045
     w := i width.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12046
     h := i height.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12047
     (i withPixelFunctionApplied:[:oldImage :oldColor :x :y |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12048
			((x between:0 and:10)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12049
			or:[(y between:0 and:10)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12050
			or:[(x between:w-10 and:w)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12051
			or:[y between:h-10 and:h]]]) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12052
			    oldColor lightened nearestIn:i colorMap
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12053
			] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12054
			    oldColor.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12055
			]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12056
		     ]) inspect.
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12057
    "
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12058
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12059
    "Modified: 24.4.1997 / 18:36:59 / cg"
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12060
!
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12061
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12062
withPixelFunctionAppliedToPixels:pixelFunctionBlock
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12063
    "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
 12064
     on the pixel values.
4296
240f73781089 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4226
diff changeset
 12065
     (read `Beyond photography, by Gerard J. Holzmann;
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12066
	   ISBM 0-13-074410-7)
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12067
     See blurred / oilPointed as examples ...)"
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12068
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12069
    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12070
	withPixelFunctionAppliedToPixels:pixelFunctionBlock
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12071
	in:(0@0 corner:width@height)
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12072
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12073
    "oil painting effect:
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12074
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12075
     |i w h|
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12076
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12077
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12078
     i inspect.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12079
     w := i width - 1.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12080
     h := i height - 1.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12081
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12082
			|b p max xMin xMax yMin yMax|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12083
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12084
			b := Bag identityNew:10.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12085
			xMin := x-3 max:0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12086
			xMax := x+3 min:w.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12087
			yMin := y-3 max:0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12088
			yMax := y+3 min:h.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12089
			xMin to:xMax do:[:tx|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12090
			  yMin to:yMax do:[:ty|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12091
			    b add:(oldImage pixelAtX:tx y:ty)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12092
			  ]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12093
			].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12094
			max := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12095
			b contents keysAndValuesDo:[:pixel :n |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12096
			    n > max ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12097
				p := pixel.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12098
				max := n
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12099
			    ]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12100
			].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12101
			p
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12102
		     ]) inspect.
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12103
    "
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12104
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12105
    "fisheye effect:
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12106
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12107
     |i w h w2 h2 R white|
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12108
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12109
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12110
     i inspect.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12111
     w := i width - 1.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12112
     h := i height - 1.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12113
     w2 := w // 2.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12114
     h2 := h // 2.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12115
     R := w2.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12116
     white := i valueFromColor:Color white.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12117
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12118
			|p r a nR nP nX nY|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12119
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12120
			p := (x-w2)@(y-h2).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12121
			r := p r.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12122
			a := p theta.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12123
			nR := r * r / R.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12124
			nP := Point r:nR theta:a.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12125
			nX := ((nP x+w2) rounded max:0) min:w.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12126
			nY := ((nP y+h2) rounded max:0) min:h.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12127
			(nX > w or:[nX < 0]) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12128
			    white
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12129
			] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12130
			    (nY > h or:[nY < 0]) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12131
				white
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12132
			    ] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12133
				oldImage pixelAtX:nX y:nY
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12134
			    ]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12135
			]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12136
		     ]) inspect.
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12137
    "
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12138
    "fisheye effect:
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12139
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12140
     |i w h w2 h2 R white|
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12141
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12142
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12143
     i inspect.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12144
     w := i width - 1.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12145
     h := i height - 1.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12146
     w2 := w // 2.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12147
     h2 := h // 2.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12148
     R := w2.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12149
     white := i valueFromColor:Color white.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12150
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12151
			|p r a nR nP nX nY|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12152
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12153
			p := (x-w2)@(y-h2).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12154
			r := p r.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12155
			a := p theta.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12156
			nR := r * r / R.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12157
			nP := Point r:nR theta:a.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12158
			nX := (nP x+w2) rounded.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12159
			nY := (nP y+h2) rounded.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12160
			(nX > w or:[nX < 0]) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12161
			    white
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12162
			] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12163
			    (nY > h or:[nY < 0]) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12164
				white
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12165
			    ] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12166
				oldImage pixelAtX:nX y:nY
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12167
			    ]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12168
			]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12169
		     ]) inspect.
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12170
    "
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12171
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12172
    "Created: 24.4.1997 / 18:37:17 / cg"
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12173
    "Modified: 24.4.1997 / 18:40:02 / cg"
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12174
!
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12175
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12176
withPixelFunctionAppliedToPixels:pixelFunctionBlock in:aRectangle
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12177
    "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
 12178
     on the pixel values.
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 12179
     (read `Beyond photography, by Gerard J. Holzmann;
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12180
	   ISBM 0-13-074410-7)
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12181
     See blurred / oilPointed as examples ...)"
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12182
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 12183
    |newImage "newBits newBytesPerRow"|
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12184
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12185
    newImage := self species new.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12186
    newImage depth:self depth.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12187
    newImage width:width.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12188
    newImage height:height.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12189
"/    newBytesPerRow := ((width * self depth) + 7) // 8.
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12190
"/    newBits := ByteArray uninitializedNew:(newBytesPerRow * height).
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12191
    newImage createPixelStore. "/ bits:newBits
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12192
    newImage photometric:photometric.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12193
    newImage samplesPerPixel:samplesPerPixel.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12194
    newImage bitsPerSample:bitsPerSample.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12195
    newImage colorMap:colorMap copy.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12196
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12197
    self applyPixelValuesTo:pixelFunctionBlock in:aRectangle into:newImage.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12198
    ^ newImage
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12199
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12200
    "oil painting effect:
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12201
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12202
     |i w h|
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12203
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12204
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12205
     i inspect.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12206
     w := i width - 1.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12207
     h := i height - 1.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12208
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12209
			|b p max xMin xMax yMin yMax|
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12210
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12211
			b := Bag identityNew:10.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12212
			xMin := x-3 max:0.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12213
			xMax := x+3 min:w.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12214
			yMin := y-3 max:0.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12215
			yMax := y+3 min:h.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12216
			xMin to:xMax do:[:tx|
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12217
			  yMin to:yMax do:[:ty|
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12218
			    b add:(oldImage pixelAtX:tx y:ty)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12219
			  ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12220
			].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12221
			max := 0.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12222
			b contents keysAndValuesDo:[:pixel :n |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12223
			    n > max ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12224
				p := pixel.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12225
				max := n
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12226
			    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12227
			].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12228
			p
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12229
		     ]) inspect.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12230
    "
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12231
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12232
    "fisheye effect:
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12233
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 12234
     |i w h w2 h2 R white|
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12235
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12236
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12237
     i inspect.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12238
     w := i width - 1.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12239
     h := i height - 1.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12240
     w2 := w // 2.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12241
     h2 := h // 2.
1510
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12242
     R := w2.
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 12243
     white := i valueFromColor:Color white.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12244
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12245
			|p r a nR nP nX nY|
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12246
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12247
			p := (x-w2)@(y-h2).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12248
			r := p r.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12249
			a := p theta.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12250
			nR := r * r / R.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12251
			nP := Point r:nR theta:a.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12252
			nX := ((nP x+w2) rounded max:0) min:w.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12253
			nY := ((nP y+h2) rounded max:0) min:h.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12254
			(nX > w or:[nX < 0]) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12255
			    white
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12256
			] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12257
			    (nY > h or:[nY < 0]) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12258
				white
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12259
			    ] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12260
				oldImage pixelAtX:nX y:nY
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12261
			    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12262
			]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12263
		     ]) inspect.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12264
    "
1510
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12265
    "fisheye effect:
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12266
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12267
     |i w h w2 h2 R white|
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12268
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12269
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
1510
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12270
     i inspect.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12271
     w := i width - 1.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12272
     h := i height - 1.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12273
     w2 := w // 2.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12274
     h2 := h // 2.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12275
     R := w2.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12276
     white := i valueFromColor:Color white.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12277
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12278
			|p r a nR nP nX nY|
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12279
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12280
			p := (x-w2)@(y-h2).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12281
			r := p r.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12282
			a := p theta.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12283
			nR := r * r / R.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12284
			nP := Point r:nR theta:a.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12285
			nX := (nP x+w2) rounded.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12286
			nY := (nP y+h2) rounded.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12287
			(nX > w or:[nX < 0]) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12288
			    white
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12289
			] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12290
			    (nY > h or:[nY < 0]) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12291
				white
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12292
			    ] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12293
				oldImage pixelAtX:nX y:nY
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12294
			    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12295
			]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12296
		     ]) inspect.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12297
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12298
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12299
    "Created: 24.4.1997 / 18:37:17 / cg"
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12300
    "Modified: 24.4.1997 / 18:40:02 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12301
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12302
3870
8245e3f37feb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
 12303
!Image methodsFor:'initialization'!
8245e3f37feb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
 12304
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12305
createPixelStore
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12306
    |bytesPerRow|
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12307
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12308
    bytesPerRow := self bytesPerRow.
5643
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
 12309
    self bits:(ByteArray new:(bytesPerRow * self height)).
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
 12310
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
 12311
    "Modified: / 02-11-2010 / 20:57:11 / cg"
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12312
!
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12313
3871
a7867fb8d880 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3870
diff changeset
 12314
initialize
3870
8245e3f37feb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
 12315
    self photometric:(self class defaultPhotometric)
8245e3f37feb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
 12316
! !
8245e3f37feb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
 12317
5037
2e515c9ee849 changed #valueFromColor:
Claus Gittinger <cg@exept.de>
parents: 4998
diff changeset
 12318
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12319
!Image methodsFor:'instance release'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12320
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12321
close
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12322
    "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
 12323
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12324
    deviceForm notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12325
	deviceForm destroy.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12326
	deviceForm := nil.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12327
    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12328
    monoDeviceForm notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12329
	monoDeviceForm destroy.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12330
	monoDeviceForm := nil.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12331
    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12332
    fullColorDeviceForm notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12333
	fullColorDeviceForm destroy.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12334
	fullColorDeviceForm := nil.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12335
    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12336
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12337
    device := nil.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12338
    mask notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12339
	mask close.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12340
    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12341
    Lobby unregister:self.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12342
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12343
    "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
 12344
    "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
 12345
!
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12346
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12347
release
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12348
    "release device resources"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12349
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12350
    device := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12351
    deviceForm := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12352
    monoDeviceForm := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12353
    fullColorDeviceForm := nil.
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
 12354
    mask notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12355
	mask release.
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
 12356
    ].
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
 12357
    Lobby unregister:self.
1746
72a583dd30bd must not forget super release
Claus Gittinger <cg@exept.de>
parents: 1739
diff changeset
 12358
    super release.
72a583dd30bd must not forget super release
Claus Gittinger <cg@exept.de>
parents: 1739
diff changeset
 12359
72a583dd30bd must not forget super release
Claus Gittinger <cg@exept.de>
parents: 1739
diff changeset
 12360
    "Modified: 11.6.1997 / 13:20:04 / cg"
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 12361
!
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 12362
4226
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12363
releaseFromDevice
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12364
    "release device resources"
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12365
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12366
    device := nil.
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12367
    deviceForm := nil.
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12368
    monoDeviceForm := nil.
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12369
    fullColorDeviceForm := nil.
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12370
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12371
    "Modified: 16.1.1997 / 19:33:01 / cg"
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12372
!
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12373
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12374
restored
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12375
    "flush device specifics after a snapin or binary restore"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12376
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12377
    self release
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12378
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12379
2227
7aa9e2a8d321 added #edit - to open an image editor.
Claus Gittinger <cg@exept.de>
parents: 2212
diff changeset
 12380
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12381
!Image methodsFor:'obsolete'!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12382
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12383
applyPixelValuesTo:pixelFunctionBlock into:newImage in:aRectangle
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12384
    "helper for withPixelFunctionAppliedToValues:
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12385
     enumerate pixelValues and evaluate the block for each.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12386
     To be redefined by subclasses for better performance."
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12387
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12388
    ^ self applyPixelValuesTo:pixelFunctionBlock in:aRectangle into:newImage
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12389
!
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12390
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12391
magnifyBy:scale
5216
f7ec910cfce1 Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 5200
diff changeset
 12392
    <resource: #obsolete>
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12393
    "obsolete: has been renamed to magnifiedBy: for ST-80 compatibility
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12394
     and name consistency ..."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12395
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12396
    self obsoleteMethodWarning.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12397
    ^ self magnifiedBy:scale
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12398
! !
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12399
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12400
!Image methodsFor:'pixel copying'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12401
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12402
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
 12403
    "replace a rectangular area by pixels from another image.
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 12404
     The sources colors must be present in the destinations
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 12405
     colorMap - otherwise, an error will be reported.
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12406
     Any mask is copied from the source.
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 12407
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12408
     WARNING:
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 12409
       This implementation is a very slow fallback general algorithm
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 12410
       (the loop over the source pixels is very slow).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12411
       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
 12412
       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
 12413
       with the same depth & palette.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12414
       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
 12415
       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
 12416
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12417
    |dX dY|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12418
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12419
    dX := srcX-dstX.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12420
    dY := srcY-dstY.
1248
6afcdec18986 commentary
Claus Gittinger <cg@exept.de>
parents: 1230
diff changeset
 12421
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12422
    ((photometric == anImage photometric)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12423
     and:[self bitsPerPixel == anImage bitsPerPixel
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12424
     and:[colorMap = anImage colorMap]]) ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12425
	"/ can loop over values
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12426
	anImage valuesFromX:srcX  y:srcY
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12427
			toX:srcX+w-1 y:srcY+h-1
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12428
			 do:[:x :y :pixelValue |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12429
	    self pixelAtX:x-dX y:y-dY put:pixelValue.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12430
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12431
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12432
	"/ must loop over colors - horribly slow
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12433
	anImage colorsFromX:srcX  y:srcY
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12434
			toX:srcX+w-1 y:srcY+h-1
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12435
			 do:[:x :y :clr |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12436
	    self colorAtX:x-dX y:y-dY put:clr.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12437
	]
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12438
    ].
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12439
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12440
    (mask isNil and:[anImage mask notNil]) ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12441
	"/ I have no mask; copied image has
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12442
	self createMask.
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12443
    ].
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12444
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12445
    mask notNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12446
	anImage mask notNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12447
	    "/ both have a mask
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12448
	    mask copyFrom:anImage mask x:srcX y:srcY toX:dstX y:dstY width:w height:h
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12449
	] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12450
	    "/ I have a mask - copied image has not
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12451
	    mask fillRectangleX:dstX y:dstY width:w height:h withValue:1
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12452
	]
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12453
"/    ] ifFalse:[
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12454
"/        anImage mask notNil ifTrue:[
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12455
"/            "/ I have no mask; copied image has (already handled)
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12456
"/        ] ifFalse:[
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12457
"/            "/ none has a mask - nothing to do.
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12458
"/        ]
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12459
    ].
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12460
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12461
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12462
     |i1 i8 i4|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12463
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12464
     i8 := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12465
     i8 inspect.
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 12466
     i1 := Image fromFile:'libtool/bitmaps/SBrowser.xbm'.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12467
     i1 inspect.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12468
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12469
     i4 := Depth4Image fromImage:i8.
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 12470
     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
 12471
     i4 inspect.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12472
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12473
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12474
    "Created: 20.9.1995 / 10:14:01 / claus"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12475
    "Modified: 20.9.1995 / 10:25:31 / claus"
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 12476
    "Modified: 21.6.1997 / 13:15:31 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12477
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12478
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12479
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
 12480
    "replace a rectangular area by pixels from another image.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12481
     The sources colors must be present in the destinations
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12482
     colorMap - otherwise, an error will be reported.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12483
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12484
     WARNING:
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12485
       This implementation is a very slow fallback general algorithm
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12486
       (the loop over the source pixels is very slow).
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12487
       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
 12488
       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
 12489
       with the same depth & palette.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12490
       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
 12491
       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
 12492
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12493
    maskedCopy ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12494
	self
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12495
	    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
 12496
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12497
	self
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12498
	    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
 12499
    ].
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12500
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12501
    "
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12502
     |i1 i8 i4|
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12503
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12504
     i8 := Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif'.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12505
     i8 inspect.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12506
     i1 := Image fromFile:'../../goodies/bitmaps/xbmBitmaps/TicTacToe.xbm'.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12507
     i1 inspect.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12508
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12509
     i4 := Depth4Image fromImage:i8.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12510
     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
 12511
     i4 inspect.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12512
    "
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12513
!
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12514
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12515
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
 12516
    "replace a rectangular area by pixels from another image.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12517
     The sources colors must be present in the destinations
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12518
     colorMap - otherwise, an error will be reported.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12519
     Only unmasked pixels are copied from the source.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12520
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12521
     WARNING:
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12522
       This implementation is a very slow fallback general algorithm
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12523
       (the loop over the source pixels is very slow).
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12524
       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
 12525
       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
 12526
       with the same depth & palette.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12527
       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
 12528
       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
 12529
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12530
    |dX dY|
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12531
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12532
    dX := srcX-dstX.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12533
    dY := srcY-dstY.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12534
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12535
    ((photometric == anImage photometric)
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12536
     and:[self bitsPerPixel == anImage bitsPerPixel
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12537
     and:[colorMap = anImage colorMap]]) ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12538
	"/ can loop over values
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12539
	anImage valuesFromX:srcX  y:srcY
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12540
			toX:srcX+w-1 y:srcY+h-1
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12541
			 do:[:x :y :pixelValue |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12542
	    (anImage maskAtX:x y:y) ~~ 0 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12543
		self pixelAtX:x-dX y:y-dY put:pixelValue.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12544
	    ]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12545
	]
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12546
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12547
	"/ must loop over colors - horribly slow
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12548
	anImage colorsFromX:srcX  y:srcY
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12549
			toX:srcX+w-1 y:srcY+h-1
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12550
			 do:[:x :y :clr |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12551
	    (anImage maskAtX:x y:y) ~~ 0 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12552
		self colorAtX:x-dX y:y-dY put:clr.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12553
	    ]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12554
	]
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12555
    ].
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12556
!
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12557
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12558
subImageIn:aRectangle
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12559
    "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
 12560
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12561
    ^ self class fromSubImage:self in:aRectangle
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12562
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12563
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12564
     |i|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12565
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 12566
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12567
     i inspect.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12568
     (i subImageIn:(300@160 corner:340@200)) inspect
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
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12571
    "Created: 20.9.1995 / 01:24:20 / claus"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12572
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12573
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12574
!Image methodsFor:'pixel functions'!
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12575
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12576
computeBitsFromPixelFunction
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12577
    "compute the bits from the pixelfunction"
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12578
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12579
    |bpr idx|
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12580
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12581
    bpr := self bytesPerRow.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12582
    bytes := ByteArray new:(bpr * height).
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12583
    idx := 1.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12584
    0 to:height-1 do:[:y |
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12585
        0 to:width-1 do:[:x |
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12586
            self pixelAtX:x y:y put:(pixelFunction value:x value:y).
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12587
        ]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12588
    ].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12589
!
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12590
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12591
pixelFunction
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12592
    ^ pixelFunction
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12593
!
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12594
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12595
pixelFunction:aTwoArgFunction
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12596
    "set the pixel function. This is used to define a functional image,
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12597
     where pixel values are computed via a function instead of coming
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12598
     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
 12599
     a pixel function).
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12600
     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
 12601
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12602
    pixelFunction := aTwoArgFunction.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12603
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12604
    "
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12605
     |i|
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12606
     i := Depth1Image extent:256@256.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12607
     i pixelFunction:[:x :y | ((x // 16) bitXor:(y // 16)) odd asInteger].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12608
     i inspect.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12609
    "
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12610
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12611
    "
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12612
     |i|
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12613
     i := Depth8Image extent:256@256.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12614
     i photometric:#blackIs0.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12615
     i pixelFunction:[:x :y | x  ].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12616
     i inspect.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12617
    "
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12618
!
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12619
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12620
pixelFunction:aTwoArgFunction inX:xInterval y:yInterval
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12621
    "set the pixel function and a viewport. 
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12622
     This is used to define a functional image,
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12623
     where pixel values are computed via a function instead of coming
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12624
     from a bits array. 
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12625
     The pixelFunction will map (x E xInterval) x (y E yInterval) -> pixel"
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12626
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12627
    |sX sY tX tY|
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12628
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12629
    "/ intervals are typically 0..1
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12630
    sX := (xInterval stop - xInterval start) asFloat / width.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12631
    sY := (yInterval stop - yInterval start) asFloat / height.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12632
    tX := xInterval start.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12633
    tY := yInterval start.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12634
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12635
    pixelFunction := 
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12636
        [:x :y | 
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12637
            aTwoArgFunction value:(x * sX + tX) value:(y * sY + tY)
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12638
        ]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12639
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12640
    "
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12641
     |i|
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12642
     i := Depth8Image extent:256@256.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12643
     i photometric:#blackIs0.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12644
     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
 12645
     i inspect.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12646
    "
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12647
! !
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12648
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12649
!Image methodsFor:'printing & storing'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12650
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12651
storeOn:aStream
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12652
    "append a printed representation of the receiver to aStream,
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12653
     from which a copy of it can be reconstructed."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12654
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12655
    |colors usedValues colorMapArray needBPS needSemi|
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12656
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12657
    needSemi := false.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12658
    aStream nextPutAll:('(%1 width:%2 height:%3' 
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12659
                            bindWith:self class name
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12660
                            with:width 
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12661
                            with:height).
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12662
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12663
    "/ 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
 12664
    "/ no need for the photometric, if it's the default anyway
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12665
    photometric ~= self class defaultPhotometric ifTrue:[
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12666
        (colorMap isNil or:[photometric ~~ #palette]) ifTrue:[
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12667
            aStream nextPutAll:' photometric:('. photometric storeOn:aStream. aStream nextPutAll:')'.
6912
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
 12668
            needSemi := false.
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12669
        ].
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12670
    ].
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12671
    aStream nextPutAll:')'.
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12672
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12673
    "/ no need to store bitPerSample/samplesPerPixel in all situations
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12674
    needBPS := true.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12675
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12676
    self depth == 1 
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12677
        ifTrue:[ needBPS := false ]
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12678
        ifFalse:[
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12679
            ((photometric == #palette) 
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12680
                and:[ (bitsPerSample size == 1)
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12681
                and:[ ((bitsPerSample at:1) == self depth)
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12682
                and:[ samplesPerPixel == 1 ]]])
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12683
            ifTrue:[
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12684
                needBPS := false.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12685
            ].
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12686
        ].
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12687
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12688
    needBPS ifTrue:[
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12689
        needSemi ifTrue:[aStream nextPutAll:';'].
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12690
        aStream nextPutAll:' bitsPerSample:('. bitsPerSample storeOn:aStream. aStream nextPutAll:')'.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12691
        samplesPerPixel ~= bitsPerSample size ifTrue:[
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12692
            aStream nextPutAll:'; samplesPerPixel:('. samplesPerPixel storeOn:aStream. aStream nextPutAll:')'. 
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12693
        ].
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12694
        needSemi := true.
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12695
    ].
5533
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 12696
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 12697
    "/ assert that all bits are there...
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 12698
    "/ self assert:(self bits size) >= (self bytesPerRow * height).
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 12699
    "/ 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
 12700
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12701
    needSemi ifTrue:[aStream nextPutAll:';'].
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12702
    aStream nextPutAll:' bits:(ByteArray fromPackedString:'. self bits asPackedString storeOn:aStream.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12703
    aStream nextPutAll:')'.
2068
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
 12704
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
 12705
    colorMap notNil ifTrue:[
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12706
        self depth <= 8 ifTrue:[
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12707
            "/ cut off unused colors ...
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12708
            usedValues := self usedValues.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12709
            colors := colorMap copyFrom:1 to:((usedValues max+1) min:colorMap size).
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12710
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12711
            colorMapArray := OrderedCollection new.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12712
            colors do:[:clr| colorMapArray add:(clr redByte); add:(clr greenByte); add:(clr blueByte)].
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12713
            aStream nextPutAll:' colorMapFromArray:'.
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12714
            colorMapArray asByteArray storeOn:aStream.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12715
        ] ifFalse:[
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12716
            aStream nextPutAll:' colorMap:('.
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12717
            colorMap storeOn:aStream.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12718
            aStream nextPutAll:')'
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12719
        ]
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12720
    ].
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
 12721
    mask notNil ifTrue:[
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12722
        aStream nextPutAll:' mask:('.
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12723
        mask storeOn:aStream.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12724
        aStream nextPutAll:')'.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12725
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12726
    aStream nextPutAll:'; yourself'
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
 12727
6912
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
 12728
    "Modified: / 22-08-1998 / 12:55:21 / cg"
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
 12729
    "Modified: / 01-09-2015 / 17:24:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 12730
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
 12731
48194c26a46c Initial revision
claus
parents:
diff changeset
 12732
!Image methodsFor:'private'!
48194c26a46c Initial revision
claus
parents:
diff changeset
 12733
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12734
bestSupportedImageFormatFor:aDevice
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12735
    "scan through the image formats as supported by aDevice,
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12736
     and return the best to use when the receiver is to be represented
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12737
     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
 12738
     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
 12739
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
 12740
    |bestDeviceDepth
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
 12741
     bestDeviceBitsPerPixel "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12742
     "maxDepth"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12743
     bestInfo maxInfo
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
 12744
     myDepth                "{ Class: SmallInteger }"
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
 12745
     maxBitsPerPixel        "{ Class: SmallInteger }"|
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12746
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12747
    myDepth := self bitsPerPixel.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12748
    maxBitsPerPixel := 0.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12749
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12750
    aDevice supportedImageFormats do:[:entry |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12751
	|deviceImageDepth        "{ Class: SmallInteger }"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12752
	 deviceImageBitsPerPixel "{ Class: SmallInteger }" |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12753
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12754
	deviceImageDepth := entry at:#depth.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12755
	deviceImageBitsPerPixel := entry at:#bitsPerPixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12756
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12757
	"/ for now, ignore all depth's which are neither 1 nor the
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12758
	"/ devices depth.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12759
	"/ (actually, many devices can handle other pixMap formats,
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12760
	"/ but I dont know (yet) how to pass the correct color info
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12761
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12762
	((deviceImageDepth == 1) or:[deviceImageDepth == aDevice depth]) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12763
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12764
	    deviceImageBitsPerPixel > maxBitsPerPixel ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12765
		maxInfo := entry.
2050
d1f21c75b5eb when asking a device for its supported pixmap formats,
Claus Gittinger <cg@exept.de>
parents: 2043
diff changeset
 12766
    "/            maxBitsPerPixel := deviceImageBitsPerPixel.
d1f21c75b5eb when asking a device for its supported pixmap formats,
Claus Gittinger <cg@exept.de>
parents: 2043
diff changeset
 12767
    "/            maxDepth := deviceImageDepth.
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12768
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12769
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12770
	    deviceImageDepth >= myDepth ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12771
		deviceImageDepth == myDepth ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12772
		    "/ take the better one ...
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12773
		    (bestDeviceDepth isNil
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12774
		     or:[(bestDeviceBitsPerPixel ~~ bestDeviceDepth)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12775
			and:[deviceImageDepth == deviceImageBitsPerPixel]]) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12776
			bestInfo := entry.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12777
			bestDeviceDepth := deviceImageDepth.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12778
			bestDeviceBitsPerPixel := deviceImageBitsPerPixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12779
		    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12780
		] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12781
		    "/ take the next-larger depth
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12782
		    (bestDeviceDepth isNil
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12783
		     or:[deviceImageBitsPerPixel < bestDeviceBitsPerPixel]) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12784
			bestInfo := entry.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12785
			bestDeviceDepth := deviceImageDepth.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12786
			bestDeviceBitsPerPixel := deviceImageBitsPerPixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12787
		    ]
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12788
		]
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12789
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12790
	].
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12791
    ].
851
c9511f8945ce fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents: 841
diff changeset
 12792
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12793
    bestDeviceDepth isNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12794
	maxBitsPerPixel == 0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12795
	    "/
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12796
	    "/ oops - nothing appropriate
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12797
	    "/
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12798
	    maxInfo notNil ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12799
		^ maxInfo
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12800
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12801
	    bestDeviceDepth := bestDeviceBitsPerPixel := aDevice depth.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12802
	    bestInfo := IdentityDictionary new.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12803
	    bestInfo at:#depth put:bestDeviceDepth.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12804
	    bestInfo at:#bitsPerPixel put:bestDeviceBitsPerPixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12805
	    bestInfo at:#padding put:32.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12806
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12807
	    bestInfo := maxInfo.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12808
	]
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12809
    ].
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
 12810
    ^ bestInfo
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
 12811
2050
d1f21c75b5eb when asking a device for its supported pixmap formats,
Claus Gittinger <cg@exept.de>
parents: 2043
diff changeset
 12812
    "Modified: / 7.2.1998 / 11:23:24 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12813
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12814
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12815
colormapFromImage:anImage
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12816
    "setup the receivers colormap from another image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12817
     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
 12818
     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
 12819
     for fromImage:/fromSubImake:"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12820
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 12821
    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
 12822
!
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 12823
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 12824
colormapFromImage:anImage photometric:photometricOrNil
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 12825
    "setup the receivers colormap from another image.
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 12826
     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
 12827
     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
 12828
     for fromImage:/fromSubImake:"
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 12829
2447
5b3d802d602b allow Image fromImage with rgb source-image and palette receiver
Claus Gittinger <cg@exept.de>
parents: 2415
diff changeset
 12830
    |usedColors|
5b3d802d602b allow Image fromImage with rgb source-image and palette receiver
Claus Gittinger <cg@exept.de>
parents: 2415
diff changeset
 12831
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12832
    samplesPerPixel == 3 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12833
	photometric := photometricOrNil ? #rgb
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12834
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12835
	photometricOrNil isNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12836
	    photometric := anImage photometric.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12837
	] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12838
	    photometric := photometricOrNil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12839
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12840
	photometric == #palette ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12841
	    self setColorMap:(anImage colorMap copy).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12842
	    "
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12843
	     must generate/compress the colormap, if source image has higher depth
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12844
	     than myself.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12845
	    "
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12846
	    (colorMap isNil
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12847
	    or:[anImage bitsPerPixel > self bitsPerPixel]) ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12848
		"
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12849
		 get used colors are extracted into our colorMap
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12850
		 (the at-put below will set the pixelValue according the
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12851
		 new colorIndex
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12852
		"
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12853
		self setColorMap:(anImage usedColors asArray).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12854
		colorMap size > (1 bitShift:self bitsPerPixel) ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12855
		    'Image [warning]: possibly too many colors in image' errorPrintCR
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12856
		]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12857
	    ]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12858
	] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12859
	    (photometric == #blackIs0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12860
	    or:[ photometric == #whiteIs0 ]) ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12861
	    ] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12862
		usedColors := anImage usedColors asArray.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12863
		usedColors size > (1 bitShift:self bitsPerPixel) ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12864
		    'Image [warning]: possibly too many colors in image' errorPrintCR.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12865
		    usedColors := usedColors copyTo:(1 bitShift:self bitsPerPixel).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12866
		].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12867
		self setColorMap:usedColors.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12868
		photometric := #palette
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12869
	    ]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12870
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12871
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12872
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12873
    "Created: 20.9.1995 / 00:58:42 / claus"
1175
5595569cfbd3 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 1170
diff changeset
 12874
    "Modified: 10.1.1997 / 17:52:21 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12875
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12876
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12877
greyByteMapForRange:range
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 12878
    "return a collection to map from pixelValues to greyLevels
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12879
     in the range 0..range.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12880
     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
 12881
     The values are rounded towards the nearest pixel."
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 12882
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
 12883
    |d clr val greyMap r
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
 12884
     n "{ Class: SmallInteger }"|
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 12885
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 12886
    r := range.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 12887
    r == 256 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12888
	r := 255
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 12889
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 12890
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 12891
    photometric == #palette ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12892
	n := colorMap size.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12893
	greyMap := ByteArray new:n.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12894
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12895
	1 to:n do:[:i |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12896
	    (clr := colorMap at:i) isNil ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12897
		"/ an unused color
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12898
		val := 0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12899
	    ] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12900
		val := (r * clr brightness) rounded
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12901
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12902
	    greyMap at:i put:val
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12903
	].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 12904
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12905
	d := self bitsPerPixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12906
	n := 1 bitShift:d.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12907
	n >= 4096 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12908
	    self error:'size not supported - too large'.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12909
	    ^ nil
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12910
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12911
	greyMap := ByteArray new:n.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12912
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12913
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12914
	photometric == #rgb ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12915
	    1 to:n do:[:i |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12916
		greyMap at:i put:(r * (self colorFromValue:i-1) brightness) rounded
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12917
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12918
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12919
	    1 to:n do:[:i |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12920
		greyMap at:i put:(r / (n-1) * (i-1)) rounded
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12921
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12922
	    photometric == #blackIs0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12923
		"/ we are done
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12924
	    ] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12925
		photometric == #whiteIs0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12926
		    greyMap reverse
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12927
		] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12928
		    self error:'invalid format'.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12929
		    ^ nil
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12930
		]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12931
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12932
	].
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12933
    ].
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 12934
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12935
    ^ greyMap
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12936
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12937
    "
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 12938
     Depth8Image new greyByteMapForRange:256
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 12939
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 12940
     Depth8Image new greyByteMapForRange:64
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 12941
     Depth4Image new greyByteMapForRange:64
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 12942
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 12943
     Depth4Image new greyByteMapForRange:1
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12944
    "
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12945
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12946
    "Created: 8.6.1996 / 08:34:14 / cg"
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
 12947
    "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
 12948
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12949
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12950
greyMapForRange:range
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12951
    "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
 12952
     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
 12953
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
 12954
    |d r clr val
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 12955
     n "{Class: SmallInteger }"
1927
d1bbdf03e5a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1919
diff changeset
 12956
     n2 "{Class: SmallInteger }"
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 12957
     greyArray|
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12958
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12959
    d := self bitsPerPixel.
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12960
    n := 1 bitShift:d.
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12961
    n >= 4096 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12962
	self error:'size not supported - too large'.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12963
	^ nil
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12964
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12965
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 12966
    greyArray := Array new:n.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12967
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12968
    photometric == #palette ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12969
	n2 := colorMap size.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12970
	1 to:n2 do:[:i |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12971
	    (clr := colorMap at:i) isNil ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12972
		"/ an unused color
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12973
		val := 0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12974
	    ] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12975
		val := range * clr brightness
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12976
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12977
	    greyArray at:i put:val
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12978
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12979
	n2 < n ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12980
	    greyArray from:n2+1 to:n put:0
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12981
	]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12982
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12983
	photometric == #rgb ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12984
	    1 to:n do:[:i |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12985
		greyArray at:i put:(range * (self colorFromValue:(i-1)) brightness)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12986
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12987
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12988
	    r := range asFloat.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12989
	    1 to:n do:[:i |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12990
		greyArray at:i put:(r / (n-1) * (i-1))
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12991
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12992
	    photometric == #blackIs0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12993
		"/ we are done
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12994
	    ] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12995
		photometric == #whiteIs0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12996
		    greyArray reverse
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12997
		] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12998
		    self error:'invalid format'.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12999
		    ^ nil
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13000
		]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13001
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13002
	]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13003
    ].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 13004
    ^ greyArray
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13005
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13006
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13007
     Depth8Image new greyMapForRange:64
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13008
     Depth4Image new greyMapForRange:64
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13009
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 13010
     Depth16Image new greyMapForRange:1
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13011
     Depth4Image new greyMapForRange:1
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 13012
     Depth2Image new greyMapForRange:1
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 13013
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 13014
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
 13015
    "Modified: 1.3.1997 / 15:48:49 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13016
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 13017
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13018
magnifyRowFrom:srcBytes offset:srcStart
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 13019
	  into:dstBytes offset:dstStart factor:mX
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13020
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13021
    "magnify a single pixel row - can only magnify by integer factors,
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13022
     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
 13023
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13024
    ^ self subclassResponsibility
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13025
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13026
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13027
makeDeviceGrayPixmapOn:aDevice depth:depth fromArray:bits
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13028
    "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
 13029
     pixels interpreted as greyValues, 0 is black,
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13030
     create a device form for it"
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13031
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13032
    |f|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13033
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 13034
    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
 13035
    f isNil ifTrue:[^ nil].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13036
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13037
    f bits:bits.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13038
    f initGC.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13039
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13040
    (aDevice blackpixel ~~ 0) ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13041
	"/ have to invert bits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13042
	f function:#copyInverted
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13043
    ].
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13044
    aDevice
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13045
	drawBits:bits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13046
	depth:depth
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13047
	padding:8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13048
	width:width height:height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13049
	x:0 y:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13050
	into:(f id)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13051
	x:0 y:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13052
	width:width height:height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13053
	with:(f gcId).
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13054
    ^ f
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13055
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13056
    "Created: 10.6.1996 / 20:10:31 / cg"
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13057
!
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13058
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13059
makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13060
    "given the bits of a monochrome bitmap, 8-bit padded and
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13061
     0-bits as black, create a device form for it"
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13062
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
 13063
"/    monoBits invert.
4769
0cabcf1481a0 Use Form class>>#width:height:fromArray:onDevice: instead of obsolete
Stefan Vogel <sv@exept.de>
parents: 4762
diff changeset
 13064
    ^ (Form width:width height:height fromArray:monoBits onDevice:aDevice)
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13065
	colorMap:(Array with:Color black with:Color white).
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13066
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13067
    "Created: 10.6.1996 / 20:18:09 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
 13068
    "Modified: 17.4.1997 / 01:07:38 / cg"
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13069
!
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13070
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13071
makeDevicePixmapOn:aDevice depth:depth fromArray:bits
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13072
    "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
 13073
     pixels interpreted as in the devices colormap,
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13074
     create a device form for it"
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13075
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13076
    |f|
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13077
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 13078
    f := Form width:width height:height depth:depth onDevice:aDevice.
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13079
    f isNil ifTrue:[^ nil].
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13080
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13081
    f bits:bits.
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13082
    f initGC.
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13083
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13084
    aDevice
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13085
	drawBits:bits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13086
	depth:depth
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13087
	padding:8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13088
	width:width height:height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13089
	x:0 y:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13090
	into:(f id)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13091
	x:0 y:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13092
	width:width height:height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13093
	with:(f gcId).
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13094
    ^ f
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13095
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13096
    "Created: 10.6.1996 / 17:56:08 / cg"
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13097
    "Modified: 10.6.1996 / 20:11:27 / cg"
5237
e28aca881988 repairPhotometric
Claus Gittinger <cg@exept.de>
parents: 5235
diff changeset
 13098
!
e28aca881988 repairPhotometric
Claus Gittinger <cg@exept.de>
parents: 5235
diff changeset
 13099
e28aca881988 repairPhotometric
Claus Gittinger <cg@exept.de>
parents: 5235
diff changeset
 13100
repairPhotometric
e28aca881988 repairPhotometric
Claus Gittinger <cg@exept.de>
parents: 5235
diff changeset
 13101
    "/ kludge: repair a 'should not happen' situation...
e28aca881988 repairPhotometric
Claus Gittinger <cg@exept.de>
parents: 5235
diff changeset
 13102
    photometric isNil ifTrue:[
6390
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
 13103
        (self depth == 24 and:[ bitsPerSample size == 3 ]) ifTrue:[
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
 13104
            photometric := #rgb
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
 13105
        ].
5237
e28aca881988 repairPhotometric
Claus Gittinger <cg@exept.de>
parents: 5235
diff changeset
 13106
    ].
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
 13107
! !
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 13108
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13109
!Image methodsFor:'queries'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13110
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13111
alphaBitsOf:pixel
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13112
    "if the receiver is an rgb-image:
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13113
     return the alpha component of a pixelValue as integer 0..maxAlphaValue.
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13114
     MaxAlphaValue is of course the largest integer representable by the number
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13115
     of alpha bits i.e. (1 bitShift:bitsAlpha)-1.
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13116
     This has to be redefined by subclasses."
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13117
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13118
    |redBits greenBits blueBits alphaBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13119
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13120
    samplesPerPixel >= 4 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13121
	redBits := bitsPerSample at:1.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13122
	greenBits := bitsPerSample at:2.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13123
	blueBits := bitsPerSample at:3.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13124
	alphaBits := bitsPerSample at:4.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13125
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13126
	^ (pixel bitShift:(redBits + greenBits + blueBits) negated)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13127
	   bitAnd:(1 bitShift:alphaBits)-1
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13128
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13129
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13130
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13131
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13132
    "Created: 8.6.1996 / 09:44:51 / cg"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13133
    "Modified: 10.6.1996 / 14:59:05 / cg"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13134
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13135
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13136
alphaMaskForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13137
    "return the mask used with translation from pixelValues to alphaBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13138
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13139
    |alphaBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13140
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13141
    samplesPerPixel >= 4 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13142
	alphaBits := bitsPerSample at:4.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13143
	^ (1 bitShift:alphaBits)-1
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13144
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13145
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13146
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13147
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13148
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13149
alphaShiftForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13150
    "return the shift amount used with translation from pixelValues to alphaBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13151
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13152
    |redBits greenBits blueBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13153
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13154
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13155
	redBits := bitsPerSample at:1.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13156
	greenBits := bitsPerSample at:2.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13157
	blueBits := bitsPerSample at:3.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13158
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13159
	^ (greenBits + blueBits + redBits) negated
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13160
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13161
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13162
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13163
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13164
3813
662c6386828e ascentOn:
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
 13165
ascentOn:aGC
662c6386828e ascentOn:
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
 13166
    "I will not draw myself above the baseline"
662c6386828e ascentOn:
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
 13167
662c6386828e ascentOn:
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
 13168
    ^ 0
662c6386828e ascentOn:
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
 13169
!
662c6386828e ascentOn:
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
 13170
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13171
averageColor
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13172
    "return the average color of the image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13173
     This usually only makes sense for textures and patterns
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13174
     (i.e. to compute shadow & light colors for viewBackgrounds).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13175
     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
 13176
     a subImage - i.e. use Image>>averageColorIn: on a smaller rectangle"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13177
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13178
    ^ self averageColorIn:(0@0 corner:(width-1)@(height-1))
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13179
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13180
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13181
averageColorIn:aRectangle
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13182
    "return the images average color in an area.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13183
     The implementation below is slow - so you may want to
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13184
     create tuned versions for DepthXImage if you plan to do
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13185
     heavy image processing ...
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13186
     (also, creating tuned versions of the enumeration messages helps a lot)"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13187
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13188
    |x0 "{ Class:SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13189
     y0 "{ Class:SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13190
     x1 "{ Class:SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13191
     y1 "{ Class:SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13192
     sumRed sumGreen sumBlue n|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13193
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13194
    sumRed := sumGreen := sumBlue := 0.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13195
    y0 := aRectangle top.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13196
    y1 := aRectangle bottom.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13197
    x0 := aRectangle left.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13198
    x1 := aRectangle right.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13199
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13200
    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
 13201
    mask isNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 13202
	self colorsFromX:x0 y:y0 toX:x1 y:y1 do:[:x :y :colorAtXY |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 13203
	    sumRed := sumRed + colorAtXY red.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 13204
	    sumGreen := sumGreen + colorAtXY green.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 13205
	    sumBlue := sumBlue + colorAtXY blue.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 13206
	].
3761
44b96cd84bb8 ignore masked pixels when computing the average
Claus Gittinger <cg@exept.de>
parents: 3760
diff changeset
 13207
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 13208
	"/ masked pixels are not counted.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 13209
	self colorsFromX:x0 y:y0 toX:x1 y:y1 do:[:x :y :colorAtXY |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 13210
	    (mask pixelAtX:x y:y) == 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 13211
		n := n - 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 13212
	    ] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 13213
		sumRed := sumRed + colorAtXY red.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 13214
		sumGreen := sumGreen + colorAtXY green.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 13215
		sumBlue := sumBlue + colorAtXY blue.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 13216
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 13217
	].
3761
44b96cd84bb8 ignore masked pixels when computing the average
Claus Gittinger <cg@exept.de>
parents: 3760
diff changeset
 13218
    ].
44b96cd84bb8 ignore masked pixels when computing the average
Claus Gittinger <cg@exept.de>
parents: 3760
diff changeset
 13219
    n == 0 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 13220
	"/ all masked
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 13221
	^ Color black
3761
44b96cd84bb8 ignore masked pixels when computing the average
Claus Gittinger <cg@exept.de>
parents: 3760
diff changeset
 13222
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13223
    ^ Color red:(sumRed / n) green:(sumGreen / n) blue:(sumBlue / n)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13224
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13225
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13226
bitsPerPixel
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13227
    "return the number of bits per pixel"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13228
5926
95dab34aeea2 changed: #bitsPerPixel
Stefan Vogel <sv@exept.de>
parents: 5919
diff changeset
 13229
    ^ bitsPerSample sum
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13230
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13231
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13232
bitsPerRow
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13233
    "return the number of bits in one scanline of the image"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13234
3868
e47cf114c824 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
 13235
    ^ width * (self bitsPerPixel).
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13236
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13237
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13238
blackComponentOfCMYK:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13239
    "if the receiver is a cmyk-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13240
     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
 13241
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13242
    samplesPerPixel == 4 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13243
	"/ assume that the cyan bits are the leftMost bits (cmyk)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13244
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13245
	bitsPerSample = #(8 8 8 8) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13246
	    ^ 100.0 / 255 * (pixel bitAnd:16rFF)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13247
	]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13248
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13249
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13250
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13251
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13252
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13253
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13254
blueBitsOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13255
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13256
     return the blue bits of a pixelValue as integer 0..maxBlueValue.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13257
     MaxGreenValue is of course the largest integer representable by the number
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13258
     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
 13259
     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
 13260
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13261
    |blueBits|
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13262
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13263
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13264
	blueBits := bitsPerSample at:3.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13265
	^ 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
 13266
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13267
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13268
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13269
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13270
    "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
 13271
    "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
 13272
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13273
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13274
blueComponentOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13275
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13276
     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
 13277
     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
 13278
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 13279
    |blueBits  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 13280
     s         "{ Class: SmallInteger }"|
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13281
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13282
    samplesPerPixel >= 3 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13283
	"/ assume that the red bits are the leftMost bits
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13284
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13285
	blueBits := bitsPerSample at:3.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13286
	blueBits == 0 ifTrue:[^ 0].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13287
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13288
	s := (1 bitShift:blueBits) - 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13289
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13290
	^ 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
 13291
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13292
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13293
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13294
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13295
    "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
 13296
    "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
 13297
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13298
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13299
blueMaskForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13300
    "return the mask used with translation from pixelValues to blueBits"
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
    |blueBits|
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
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13305
	blueBits := bitsPerSample at:3.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13306
	^ (1 bitShift:blueBits)-1
3490
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
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13309
    self subclassResponsibility
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
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13312
blueShiftForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13313
    "return the shift amount used with translation from pixelValues to blueBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13314
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13315
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13316
	^ 0
3490
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
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13319
    self subclassResponsibility
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
680
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 13322
bounds
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 13323
    "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
 13324
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 13325
    ^ 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
 13326
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 13327
    "Created: 13.5.1996 / 10:27:06 / cg"
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 13328
!
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 13329
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13330
brightness
6755
cee1206f74db class: Image
Claus Gittinger <cg@exept.de>
parents: 6653
diff changeset
 13331
    "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
 13332
     This usually only makes sense for textures and patterns
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13333
     (i.e. to compute shadow & light colors for viewBackgrounds).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13334
     Notice, that for the above purpose, only a subimage is inspected here"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13335
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13336
    ^ (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
 13337
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13338
    "Modified: 8.6.1996 / 08:46:46 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13339
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13340
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13341
bytesPerRow
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13342
    "return the number of bytes in one scanline of the image"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13343
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13344
    |bitsPerRow bytesPerRow|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13345
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13346
    bitsPerRow := width * (self bitsPerPixel).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13347
    bytesPerRow := bitsPerRow // 8.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13348
    ((bitsPerRow \\ 8) ~~ 0) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13349
	bytesPerRow := bytesPerRow + 1
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13350
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13351
    ^ bytesPerRow
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
1993
b3cf63f64e15 added query for padded bytesPerLine
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
 13354
bytesPerRowPaddedTo:padding
b3cf63f64e15 added query for padded bytesPerLine
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
 13355
    "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
 13356
     if scanlines are to be padded to padding-bits."
b3cf63f64e15 added query for padded bytesPerLine
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
 13357
2005
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
 13358
    ^ self class
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13359
	bytesPerRowForWidth:width depth:(self bitsPerPixel) padding:padding
1993
b3cf63f64e15 added query for padded bytesPerLine
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
 13360
!
b3cf63f64e15 added query for padded bytesPerLine
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
 13361
1935
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 13362
center
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 13363
    "for compatibility with GC protocol - return the centerPoint"
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 13364
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 13365
    ^ (width // 2) @ (height // 2)
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 13366
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 13367
    "Created: 22.10.1997 / 23:52:40 / cg"
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 13368
!
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 13369
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13370
colorFromValue:pixelValue
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13371
    "given a pixel value, return the corresponding color.
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13372
     Pixel values start with 0.
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13373
     The implementation below is generic and slow
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13374
     - 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
 13375
5126
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
 13376
    |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
 13377
     numRedBits numGreenBits numBlueBits numAlphaBits|
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 13378
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 13379
    p := photometric.
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 13380
    p isNil ifTrue:[
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13381
        colorMap notNil ifTrue:[
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13382
            p := #palette
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13383
        ] ifFalse:[
7191
cbd86b610b20 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7180
diff changeset
 13384
            "/ 'Image [warning]: no photometric - assume greyscale' infoPrintCR
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13385
            p := #blackIs0
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13386
        ]
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 13387
    ].
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 13388
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 13389
    p == #blackIs0 ifTrue:[
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13390
        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13391
        ^ Color gray:(pixelValue * (100 / maxPixel)).
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13392
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13393
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 13394
    p == #whiteIs0 ifTrue:[
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13395
        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13396
        ^ 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
 13397
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13398
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 13399
    p == #palette ifTrue:[
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13400
        pixelValue >= colorMap size ifTrue:[
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13401
            ^ Color black
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13402
        ].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13403
        clr := colorMap at:(pixelValue + 1).
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13404
        clr isNil ifTrue:[
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13405
            ^ Color black.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13406
        ].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13407
        ^ clr.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13408
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13409
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 13410
    p == #rgb ifTrue:[
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13411
        r := self redBitsOf:pixelValue.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13412
        g := self greenBitsOf:pixelValue.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13413
        b := self blueBitsOf:pixelValue.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13414
        "/ scale...
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13415
        numRedBits := bitsPerSample at:1.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13416
        numGreenBits := bitsPerSample at:2.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13417
        numBlueBits := bitsPerSample at:3.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13418
        r := (r = 0) ifTrue:[0] ifFalse:[(100 / ((1 bitShift:numRedBits)-1) * r)].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13419
        g := (g = 0) ifTrue:[0] ifFalse:[(100 / ((1 bitShift:numGreenBits)-1) * g)].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13420
        b := (b = 0) ifTrue:[0] ifFalse:[(100 / ((1 bitShift:numBlueBits)-1) * b)].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13421
        ^ Color redPercent:r greenPercent:g bluePercent:b
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 13422
    ].
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 13423
7123
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 13424
    ((p == #rgba) or:[p == #argb]) ifTrue:[
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13425
        r := self redBitsOf:pixelValue.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13426
        g := self greenBitsOf:pixelValue.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13427
        b := self blueBitsOf:pixelValue.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13428
        a := self alphaBitsOf:pixelValue.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13429
        "/ scale...
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13430
        numRedBits := bitsPerSample at:1.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13431
        numGreenBits := bitsPerSample at:2.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13432
        numBlueBits := bitsPerSample at:3.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13433
        numAlphaBits := bitsPerSample at:4.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13434
        r := (r = 0) ifTrue:[0] ifFalse:[(100 / ((1 bitShift:numRedBits)-1) * r)].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13435
        g := (g = 0) ifTrue:[0] ifFalse:[(100 / ((1 bitShift:numGreenBits)-1) * g)].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13436
        b := (b = 0) ifTrue:[0] ifFalse:[(100 / ((1 bitShift:numBlueBits)-1) * b)].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13437
        a := (a = 0) ifTrue:[0] ifFalse:[(100 / ((1 bitShift:numAlphaBits)-1) * a)].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13438
        ^ 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
 13439
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13440
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13441
    p == #cmyk ifTrue:[
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13442
        c := self cyanComponentOfCMYK:pixelValue.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13443
        m := self magentaComponentOfCMYK:pixelValue.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13444
        y := self yellowComponentOfCMYK:pixelValue.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13445
        k := self blackComponentOfCMYK:pixelValue.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13446
        ^ 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
 13447
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13448
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13449
    p == #cmy ifTrue:[
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13450
        c := self cyanComponentOfCMY:pixelValue.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13451
        m := self magentaComponentOfCMY:pixelValue.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13452
        y := self yellowComponentOfCMY:pixelValue.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13453
        ^ Color cyan:c magenta:m yellow:y.
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13454
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13455
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13456
    self error:'invalid (unsupported) photometric'
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13457
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 13458
    "Created: / 08-06-1996 / 08:46:18 / cg"
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 13459
    "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
 13460
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13461
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13462
cyanComponentOfCMY:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13463
    "if the receiver is a cmy-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13464
     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
 13465
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13466
    samplesPerPixel == 3 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13467
	"/ assume that the cyan bits are the leftMost bits (cmy)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13468
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13469
	bitsPerSample = #(8 8 8) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13470
	    ^ 100.0 / 255 * ((pixel bitShift:-16) bitAnd:16rFF)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13471
	]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13472
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13473
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13474
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13475
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13476
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13477
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13478
cyanComponentOfCMYK:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13479
    "if the receiver is a cmyk-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13480
     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
 13481
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13482
    samplesPerPixel == 4 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13483
	"/ assume that the cyan bits are the leftMost bits (cmyk)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13484
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13485
	bitsPerSample = #(8 8 8 8) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13486
	    ^ 100.0 / 255 * ((pixel bitShift:-24) bitAnd:16rFF)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13487
	]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13488
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13489
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13490
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13491
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13492
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13493
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13494
greenBitsOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13495
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13496
     return the green bits of a pixelValue as integer 0..maxGreenValue.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13497
     MaxGreenValue is of course the largest integer representable by the number
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13498
     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
 13499
     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
 13500
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13501
    |blueBits greenBits|
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13502
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13503
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13504
	greenBits := bitsPerSample at:2.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13505
	blueBits := bitsPerSample at:3.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13506
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13507
	^ (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
 13508
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13509
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13510
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13511
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13512
    "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
 13513
    "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
 13514
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13515
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13516
greenComponentOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13517
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13518
     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
 13519
     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
 13520
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 13521
    |greenBits "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 13522
     blueBits  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 13523
     s         "{ Class: SmallInteger }"|
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13524
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13525
    samplesPerPixel >= 3 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13526
	"/ assume that the red bits are the leftMost bits
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13527
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13528
	greenBits := bitsPerSample at:2.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13529
	greenBits == 0 ifTrue:[^ 0].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13530
	blueBits := bitsPerSample at:3.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13531
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13532
	s := (1 bitShift:greenBits) - 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13533
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13534
	^ 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
 13535
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13536
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13537
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13538
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13539
    "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
 13540
    "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
 13541
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13542
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13543
greenMaskForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13544
    "return the mask used with translation from pixelValues to greenBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13545
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13546
    |greenBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13547
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13548
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13549
	greenBits := bitsPerSample at:2.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13550
	^ (1 bitShift:greenBits)-1
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13551
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13552
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13553
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13554
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13555
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13556
greenShiftForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13557
    "return the shift amount used with translation from pixelValues to greenBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13558
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 13559
    |greenBits|
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13560
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13561
    samplesPerPixel >= 3 ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13562
	greenBits := bitsPerSample at:3.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13563
	^ greenBits negated
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13564
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13565
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13566
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13567
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13568
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13569
heightOn:aGC
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13570
    "return my height, if displayed on aGC;
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13571
     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
 13572
     return the pixel-height"
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13573
680
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 13574
    ^ height
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13575
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13576
    "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
 13577
    "Modified: 13.5.1996 / 10:26:36 / cg"
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13578
!
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13579
3700
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 13580
isDithered
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 13581
    "for compatibility with color protocol"
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 13582
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 13583
    ^ false
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 13584
!
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 13585
3507
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 13586
isGrayscaleImage
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 13587
    ^ (photometric ~= #palette)
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 13588
      and:[photometric ~= #rgb]
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 13589
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 13590
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 13591
    "Created: 22.4.1997 / 14:12:02 / cg"
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 13592
!
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 13593
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13594
isImage
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13595
    "return true, if the receiver is some kind of image;
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13596
     true is returned here - the method is redefined from Object."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13597
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13598
    ^ true
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13599
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13600
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13601
isImageOrForm
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13602
    "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
 13603
     true is returned here - the method is redefined from Object."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13604
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13605
    ^ true
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13606
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13607
1630
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 13608
isMask
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 13609
    ^ false
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 13610
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 13611
    "Created: 22.4.1997 / 14:12:02 / cg"
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 13612
!
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 13613
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13614
magentaComponentOfCMY:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13615
    "if the receiver is a cmy-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13616
     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
 13617
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13618
    samplesPerPixel == 3 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13619
	"/ assume that the cyan bits are the leftMost bits (cmy)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13620
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13621
	bitsPerSample = #(8 8 8) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13622
	    ^ 100.0 / 255 * ((pixel bitShift:-8) bitAnd:16rFF)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13623
	]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13624
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13625
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13626
    self subclassResponsibility
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
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13630
magentaComponentOfCMYK:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13631
    "if the receiver is a cmyk-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13632
     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
 13633
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13634
    samplesPerPixel == 4 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13635
	"/ assume that the cyan bits are the leftMost bits (cmyk)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13636
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13637
	bitsPerSample = #(8 8 8 8) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13638
	    ^ 100.0 / 255 * ((pixel bitShift:-16) bitAnd:16rFF)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13639
	]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13640
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13641
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13642
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13643
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
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 13646
pixelArraySpecies
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 13647
    "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
 13648
6648
dc88bb5f9231 class: Image
Claus Gittinger <cg@exept.de>
parents: 6624
diff changeset
 13649
    |d|
dc88bb5f9231 class: Image
Claus Gittinger <cg@exept.de>
parents: 6624
diff changeset
 13650
dc88bb5f9231 class: Image
Claus Gittinger <cg@exept.de>
parents: 6624
diff changeset
 13651
    (d := self depth) <= 8 ifTrue:[^ ByteArray].
dc88bb5f9231 class: Image
Claus Gittinger <cg@exept.de>
parents: 6624
diff changeset
 13652
    "/ d <= 16 ifTrue:[^ WordArray].
dc88bb5f9231 class: Image
Claus Gittinger <cg@exept.de>
parents: 6624
diff changeset
 13653
    "/ ^ IntegerArray
dc88bb5f9231 class: Image
Claus Gittinger <cg@exept.de>
parents: 6624
diff changeset
 13654
    ^ Array
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 13655
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 13656
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13657
realColorMap
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13658
    "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
 13659
     For palette images, this is the internal colormap;
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13660
     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
 13661
     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
 13662
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13663
    |d nEntries "{ Class: SmallInteger }"
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13664
     colorArray|
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13665
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13666
    photometric == #palette ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13667
	^ colorMap asArray
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13668
    ].
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13669
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13670
    d := self depth.
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13671
    d > 12 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13672
	self error:'deep palette images not supported'.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13673
	^ nil.
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13674
    ].
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13675
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13676
    nEntries := 1 bitShift:d.
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13677
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13678
    colorArray := Array new:nEntries.
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13679
    1 to:nEntries do:[:idx |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13680
	colorArray at:idx put:(self colorFromValue:(idx-1)).
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13681
    ].
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13682
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13683
    ^ colorArray
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13684
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13685
    "Created: 11.7.1996 / 20:20:35 / cg"
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13686
    "Modified: 11.7.1996 / 20:49:21 / cg"
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13687
!
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13688
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13689
realUsedColors
3964
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 13690
    "return a collection of colors which are really used in the receiver.
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 13691
     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
 13692
     (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
 13693
6379
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
 13694
    ^ self realUsedValues collect:[:pixel | self colorFromValue:pixel] as:Set
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13695
!
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13696
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13697
realUsedValues
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13698
    "return a collection of color values used in the receiver.
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13699
     Notice, that the interpretation of the pixels depends on the photometric
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13700
     of the image.
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13701
     This is a general and therefore slow implementation; subclasses
3964
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 13702
     may want to redefine this method for more performance.
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 13703
     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
 13704
     (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
 13705
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13706
    |set last|
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13707
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13708
    set := IdentitySet new.
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13709
    self valuesFromX:0 y:0 toX:(self width-1) y:(self height-1) do:[:x :y :pixel |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13710
	pixel ~~ last ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13711
	    set add:pixel.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13712
	    last := pixel.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13713
	]
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13714
    ].
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13715
    ^ set
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13716
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13717
    "
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 13718
     (Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') usedValues
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 13719
     (Image fromFile:'libtool/bitmaps/SBrowser.xbm') usedValues
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13720
    "
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13721
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13722
    "Modified: / 29.7.1998 / 21:29:44 / cg"
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13723
!
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13724
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13725
redBitsOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13726
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13727
     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
 13728
     MaxRedValue is the largest integer representable by the number
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13729
     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
 13730
     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
 13731
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13732
    |redBits greenBits blueBits|
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13733
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13734
    samplesPerPixel >= 3 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13735
	redBits := bitsPerSample at:1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13736
	greenBits := bitsPerSample at:2.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13737
	blueBits := bitsPerSample at:3.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13738
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13739
	^ (pixel bitShift:(greenBits + blueBits) negated)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13740
	   bitAnd:(1 bitShift:redBits)-1
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13741
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13742
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13743
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13744
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13745
    "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
 13746
    "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
 13747
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13748
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13749
redComponentOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13750
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13751
     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
 13752
     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
 13753
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 13754
    |redBits   "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 13755
     greenBits "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 13756
     blueBits  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 13757
     s         "{ Class: SmallInteger }"|
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13758
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13759
    samplesPerPixel >= 3 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13760
	"/ assume that the red bits are the leftMost bits
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13761
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13762
	redBits := bitsPerSample at:1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13763
	redBits == 0 ifTrue:[^ 0].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13764
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13765
	greenBits := bitsPerSample at:2.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13766
	blueBits := bitsPerSample at:3.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13767
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13768
	s := (1 bitShift:redBits) - 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13769
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13770
	^ 100.0 / s *
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13771
	  ((pixel bitShift:(greenBits + blueBits) negated)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13772
	   bitAnd:(1 bitShift:redBits)-1)
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13773
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13774
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13775
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13776
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13777
    "Created: 8.6.1996 / 08:45:30 / cg"
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 13778
    "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
 13779
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13780
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13781
redMaskForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13782
    "return the mask used with translation from pixelValues to redBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13783
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13784
    |redBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13785
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13786
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13787
	redBits := bitsPerSample at:1.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13788
	^ (1 bitShift:redBits)-1
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13789
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13790
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13791
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13792
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13793
    "Created: 8.6.1996 / 09:44:51 / cg"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13794
    "Modified: 10.6.1996 / 14:59:05 / cg"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13795
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13796
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13797
redShiftForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13798
    "return the shift amount used with translation from pixelValues to redBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13799
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13800
    |greenBits blueBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13801
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13802
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13803
	greenBits := bitsPerSample at:2.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13804
	blueBits := bitsPerSample at:3.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13805
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13806
	^ (greenBits + blueBits) negated
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13807
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13808
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13809
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13810
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13811
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13812
rgbFromValue:pixelValue
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13813
    "given a pixel value, return the corresponding 24bit rgbValue (rrggbb, red is MSB).
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13814
     Pixel value is in 0..2^depth - 1.
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13815
     The implementation below is generic and slow
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13816
     - this method is typically redefined in subclasses."
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13817
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13818
    |p maxPixel clr r g b c m y k|
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13819
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13820
    p := photometric.
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13821
    p isNil ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13822
	colorMap notNil ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13823
	    p := #palette
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13824
	] ifFalse:[
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13825
"/            'Image [warning]: no photometric - assume greyscale' infoPrintCR
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13826
	    p := #blackIs0
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13827
	]
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13828
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13829
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13830
    p == #blackIs0 ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13831
	maxPixel := (1 bitShift:self bitsPerPixel) - 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13832
	b := pixelValue * 255 // maxPixel.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13833
	^ (((b bitShift:8) bitOr:b) bitShift:8) bitOr:b
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13834
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13835
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13836
    p == #whiteIs0 ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13837
	maxPixel := (1 bitShift:self bitsPerPixel) - 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13838
	b := 255 - (pixelValue * 255 // maxPixel).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13839
	^ (((b bitShift:8) bitOr:b) bitShift:8) bitOr:b
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13840
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13841
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13842
    p == #palette ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13843
	pixelValue >= colorMap size ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13844
	    ^ 0 "/ black
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13845
	].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13846
	clr := colorMap at:(pixelValue + 1).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13847
	clr isNil ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13848
	    ^ 0 "/ black
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13849
	].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13850
	^ clr rgbValue.
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13851
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13852
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13853
    p == #rgb ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13854
	r := self redBitsOf:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13855
	g := self greenBitsOf:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13856
	b := self blueBitsOf:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13857
	"/ must scale to byte value...
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13858
	r := r bitShift:(8 - (bitsPerSample at:1)).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13859
	g := g bitShift:(8 - (bitsPerSample at:2)).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13860
	b := b bitShift:(8 - (bitsPerSample at:3)).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13861
	^ (((r bitShift:8) bitOr:g) bitShift:8) bitOr:b
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13862
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13863
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13864
    p == #cmyk ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13865
	c := self cyanComponentOfCMYK:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13866
	m := self magentaComponentOfCMYK:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13867
	y := self yellowComponentOfCMYK:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13868
	k := self blackComponentOfCMYK:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13869
	^ (Color cyan:c magenta:m yellow:y black:k) rgbValue.
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13870
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13871
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13872
    p == #cmy ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13873
	c := self cyanComponentOfCMY:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13874
	m := self magentaComponentOfCMY:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13875
	y := self yellowComponentOfCMY:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13876
	^ (Color cyan:c magenta:m yellow:y) rgbValue.
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13877
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13878
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13879
    self error:'invalid (unsupported) photometric'
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13880
!
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13881
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13882
usedColors
3964
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 13883
    "return a collection of colors used in the receiver.
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 13884
     This looks at the colorMap only if present.
6896
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13885
     (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
 13886
2311
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13887
    |colors|
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13888
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13889
    colors := self usedColorsMax:4096.
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13890
    colors isNil ifTrue:[
6896
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13891
        self error:'too many colors in image'.
2311
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13892
    ].
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13893
    ^ colors
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13894
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13895
    "
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 13896
     (Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') usedColors
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 13897
     (Image fromFile:'libtool/bitmaps/SBrowser.xbm') usedColors
2311
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13898
    "
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13899
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13900
    "Modified: / 7.9.1998 / 17:56:12 / cg"
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13901
!
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13902
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13903
usedColorsMax:nMax
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13904
    "return a collection of colors used in the receiver;
3964
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 13905
     This looks at the colorMap only if present
6896
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13906
     (as opposed to #realUsedColors, which goes through the pixels of the bitmap).
3964
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 13907
     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
 13908
     (useful when searching rgb images)."
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13909
2199
ac56b54c59a5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2185
diff changeset
 13910
    |usedValues max colors|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13911
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13912
    photometric == #rgb ifTrue:[
6896
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13913
        usedValues := IdentitySet new.
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13914
        self valuesFromX:0 y:0 toX:(width-1) y:(height-1)
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13915
          do:[:x :y :pixel |
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13916
            usedValues add:pixel.
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13917
            usedValues size > nMax ifTrue:[
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13918
                "/ too many to be returned here (think of the mass of
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13919
                "/ data to be returned by a 24bit image ... ;-)
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13920
                ^ nil
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13921
            ]
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13922
        ].
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13923
        "/ code below is slightly faster ...
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13924
        "/ colors := usedValues collect:[:pixel | self colorFromValue:pixel].
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13925
        colors := usedValues collect:[:pixel | |r g b|
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13926
                                        r := self redBitsOf:pixel.
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13927
                                        g := self greenBitsOf:pixel.
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13928
                                        b := self blueBitsOf:pixel.
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13929
                                        "/ must scale to byte value...
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13930
                                        r := r bitShift:(8 - (bitsPerSample at:1)).
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13931
                                        g := g bitShift:(8 - (bitsPerSample at:2)).
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13932
                                        b := b bitShift:(8 - (bitsPerSample at:3)).
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13933
                                        Color redByte:r greenByte:g blueByte:b
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13934
                                     ].
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13935
        ^ colors.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13936
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13937
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13938
    usedValues := self usedValues asArray.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13939
    photometric == #palette ifTrue:[
6896
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13940
        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
 13941
    ] ifFalse:[
6896
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13942
        "/ (photometric == #blackIs0 or:[photometric == #whiteIs0])
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13943
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13944
        max := (1 bitShift:self depth) - 1.
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13945
        colors :=  usedValues collect:[:val | (Color gray:(100 * val / max ))] as:Set.
6037
eea2343b0b1e Refactoring:
Stefan Vogel <sv@exept.de>
parents: 5956
diff changeset
 13946
    ].
eea2343b0b1e Refactoring:
Stefan Vogel <sv@exept.de>
parents: 5956
diff changeset
 13947
    ^ colors
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13948
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13949
    "
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 13950
     (Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') usedColors
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 13951
     (Image fromFile:'libtool/bitmaps/SBrowser.xbm') usedColors
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13952
    "
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
 13953
2311
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13954
    "Created: / 7.9.1998 / 17:54:17 / cg"
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13955
    "Modified: / 7.9.1998 / 17:56:21 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13956
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13957
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13958
usedValues
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13959
    "return a collection of color values used in the receiver.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13960
     Notice, that the interpretation of the pixels depends on the photometric
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13961
     of the image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13962
     This is a general and therefore slow implementation; subclasses
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13963
     may want to redefine this method for more performance."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13964
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13965
    ^ self realUsedValues
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13966
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13967
    "
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 13968
     (Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') usedValues
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 13969
     (Image fromFile:'lib tool/bitmaps/SBrowser.xbm') usedValues
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13970
    "
2206
8bf0549762b8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2205
diff changeset
 13971
8bf0549762b8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2205
diff changeset
 13972
    "Modified: / 29.7.1998 / 21:29:44 / cg"
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13973
!
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13974
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13975
valueFromColor:color
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13976
    "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
 13977
     Non-representable colors return nil."
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13978
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 13979
    |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
 13980
5051
492727d3e5f3 oops valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 5037
diff changeset
 13981
    color colorId notNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13982
	color == Color noColor ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13983
	    ^ nil "/ mask
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13984
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13985
	color device isNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13986
	    ^ color colorId
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13987
	]
5051
492727d3e5f3 oops valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 5037
diff changeset
 13988
    ].
5037
2e515c9ee849 changed #valueFromColor:
Claus Gittinger <cg@exept.de>
parents: 4998
diff changeset
 13989
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13990
    photometric == #whiteIs0 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13991
	maxPixel := (1 bitShift:self bitsPerPixel) - 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13992
	^ maxPixel - (color brightness * maxPixel) rounded.
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13993
    ].
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13994
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13995
    photometric == #blackIs0 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13996
	maxPixel := (1 bitShift:self bitsPerPixel) - 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13997
	^ (color brightness * maxPixel) rounded.
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13998
    ].
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13999
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14000
    photometric == #palette ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14001
	colorMap isNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14002
	    "/ same as blackIs0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14003
	    maxPixel := (1 bitShift:self bitsPerPixel) - 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14004
	    ^ (color brightness * maxPixel) rounded.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14005
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14006
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14007
	pixel := colorMap indexOf:color.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14008
	pixel == 0 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14009
	    "
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14010
	     the color is not in the images colormap
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14011
	    "
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14012
	    ^ nil
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14013
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14014
	^ pixel - 1
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14015
    ].
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14016
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14017
    photometric == #rgb ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14018
	samplesPerPixel >= 3 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14019
	    redBits := bitsPerSample at:1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14020
	    greenBits := bitsPerSample at:2.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14021
	    blueBits := bitsPerSample at:3.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14022
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14023
	    "/ map r/g/b to 0..255
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14024
	    r := (color red / 100.0 * ((1 bitShift:redBits)-1)) rounded.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14025
	    g := (color green / 100.0 * ((1 bitShift:greenBits)-1)) rounded.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14026
	    b := (color blue / 100.0 * ((1 bitShift:blueBits)-1)) rounded.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14027
	    pixel := (((r bitShift:greenBits) + g) bitShift:blueBits) + b.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14028
	    ^ pixel
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14029
	]
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14030
    ].
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14031
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 14032
    photometric == #rgba ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14033
	samplesPerPixel >= 4 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14034
	    redBits := bitsPerSample at:1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14035
	    greenBits := bitsPerSample at:2.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14036
	    blueBits := bitsPerSample at:3.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14037
	    alphaBits := bitsPerSample at:4.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14038
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14039
	    "/ map r/g/b/a to 0..255
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14040
	    r := (color red / 100.0 * ((1 bitShift:redBits)-1)) rounded.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14041
	    g := (color green / 100.0 * ((1 bitShift:greenBits)-1)) rounded.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14042
	    b := (color blue / 100.0 * ((1 bitShift:blueBits)-1)) rounded.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14043
	    a := (color alpha * ((1 bitShift:alphaBits)-1)) rounded.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14044
	    pixel := (((((a bitShift:redBits) + r) bitShift:greenBits) + g) bitShift:blueBits) + b.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14045
	    ^ pixel
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14046
	]
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 14047
    ].
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
 14048
    ImageErrorSignal raiseErrorString:'format not supported'.
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14049
    ^ nil
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14050
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 14051
    "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
 14052
!
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14053
4858
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14054
valueFromRGB:rgb
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14055
    "given a color, return the corresponding pixel value.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14056
     Non-representable colors return nil."
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14057
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14058
    |pixel redBits greenBits blueBits alphaBits r g b a|
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14059
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14060
    r := rgb bitAnd:16rFF.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14061
    g := (rgb bitShift:-8) bitAnd:16rFF.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14062
    b := (rgb bitShift:-16) bitAnd:16rFF.
7123
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 14063
    a := 255.
4858
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14064
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14065
"/    photometric == #whiteIs0 ifTrue:[
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14066
"/        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14067
"/        ^ maxPixel - (color brightness * maxPixel) rounded.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14068
"/    ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14069
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14070
"/    photometric == #blackIs0 ifTrue:[
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14071
"/        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14072
"/        ^ (color brightness * maxPixel) rounded.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14073
"/    ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14074
"/
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14075
"/    photometric == #palette ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14076
"/        colorMap isNil ifTrue:[
4858
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14077
"/            "/ same as blackIs0
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14078
"/            maxPixel := (1 bitShift:self bitsPerPixel) - 1.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14079
"/            ^ (color brightness * maxPixel) rounded.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14080
"/        ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14081
"/
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14082
"/        pixel := colorMap indexOf:color.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14083
"/        pixel == 0 ifTrue:[
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14084
"/            "
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14085
"/             the color is not in the images colormap
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14086
"/            "
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14087
"/            ^ nil
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14088
"/        ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14089
"/        ^ pixel - 1
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14090
"/    ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14091
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14092
    photometric == #rgb ifTrue:[
7123
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 14093
        samplesPerPixel >= 3 ifTrue:[
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 14094
            "/ r,g,b  b at low end
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 14095
            redBits := bitsPerSample at:1.
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 14096
            greenBits := bitsPerSample at:2.
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 14097
            blueBits := bitsPerSample at:3.
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 14098
            pixel := (((r bitShift:greenBits) + g) bitShift:blueBits) + b.
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 14099
            ^ pixel
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 14100
        ]
4858
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14101
    ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14102
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14103
    photometric == #rgba ifTrue:[
7123
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 14104
        samplesPerPixel >= 4 ifTrue:[
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 14105
            "/ a,r,g,b  b at low end
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 14106
            redBits := bitsPerSample at:1.
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 14107
            greenBits := bitsPerSample at:2.
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 14108
            blueBits := bitsPerSample at:3.
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 14109
            alphaBits := bitsPerSample at:4.
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 14110
            pixel := (((((a bitShift:redBits) + r) bitShift:greenBits) + g) bitShift:blueBits) + b.
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 14111
            ^ pixel
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 14112
        ]
4858
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14113
    ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14114
    ImageErrorSignal raiseErrorString:'format not supported'.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14115
    ^ nil
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14116
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14117
    "Created: / 15-01-2008 / 15:55:08 / cg"
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14118
!
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14119
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14120
valueFromRedBits:redBits greenBits:greenBits blueBits:blueBits
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14121
    "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
 14122
     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
 14123
     For now, only useful with RGB images"
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14124
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14125
    |pixel numGreenBits numBlueBits|
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14126
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14127
    photometric == #rgb ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14128
	samplesPerPixel >= 3 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14129
	    numGreenBits := bitsPerSample at:2.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14130
	    numBlueBits := bitsPerSample at:3.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14131
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14132
	    pixel := (((redBits bitShift:numGreenBits) + greenBits) bitShift:numBlueBits) + blueBits.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14133
	    ^ pixel
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14134
	]
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14135
    ].
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14136
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14137
    ImageErrorSignal raiseErrorString:'format not supported'.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14138
    ^ nil
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14139
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14140
    "Modified: / 30.9.1998 / 22:03:50 / cg"
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14141
!
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14142
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 14143
widthOn:aGC
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 14144
    "return my width, if displayed on aGC;
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 14145
     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
 14146
     return the pixel-width"
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 14147
680
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 14148
    ^ width
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 14149
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 14150
    "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
 14151
    "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
 14152
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14153
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14154
yellowComponentOfCMY:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14155
    "if the receiver is a cmy-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14156
     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
 14157
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14158
    samplesPerPixel == 3 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14159
	"/ assume that the cyan bits are the leftMost bits (cmy)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14160
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14161
	bitsPerSample = #(8 8 8) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14162
	    ^ 100.0 / 255 * (pixel bitAnd:16rFF)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14163
	]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14164
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14165
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14166
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14167
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14168
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14169
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14170
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14171
yellowComponentOfCMYK:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14172
    "if the receiver is a cmyk-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14173
     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
 14174
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14175
    samplesPerPixel == 4 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14176
	"/ assume that the cyan bits are the leftMost bits (cmyk)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14177
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14178
	bitsPerSample = #(8 8 8 8) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14179
	    ^ 100.0 / 255 * ((pixel bitShift:-8) bitAnd:16rFF)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14180
	]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14181
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14182
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14183
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14184
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14185
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14186
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14187
!Image methodsFor:'saving on file'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14188
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14189
saveOn:aFileName
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14190
    "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
 14191
     Currently, not all formats may be supported
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 14192
     (see ImageReader subclasses implementing save:onFile:).
3913
25e103c84773 comments
Claus Gittinger <cg@exept.de>
parents: 3912
diff changeset
 14193
     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
 14194
7173
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14195
    ^ self saveOn:aFileName quality:nil
1175
5595569cfbd3 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 1170
diff changeset
 14196
1385
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 14197
    "
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 14198
     |image|
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 14199
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14200
     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
 14201
     image saveOn:'myImage.tiff'.
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 14202
     image saveOn:'myImage.xbm'.
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 14203
     image saveOn:'myImage.xpm'.
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 14204
     image saveOn:'myImage.xwd'.
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 14205
    "
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 14206
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
 14207
    "Modified: 30.6.1997 / 22:06:34 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 14208
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 14209
7173
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14210
saveOn:aFileName quality:qualityPercentOrNil
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14211
    "save the image in aFileName. The suffix of the filename controls the format.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14212
     Currently, not all formats may be supported
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14213
     (see ImageReader subclasses implementing save:onFile:).
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14214
     May raise a signal, if the image cannot be written by the reader."
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14215
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14216
    |suffix readerClass|
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14217
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14218
    "/
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14219
    "/ from the extension, get the imageReader class
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14220
    "/ (which should know how to write images as well)
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14221
    "/
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14222
    suffix := aFileName asFilename suffix.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14223
    readerClass := MIMETypes imageReaderForSuffix:suffix.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14224
    readerClass isNil ifTrue:[        
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14225
        "/
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14226
        "/ no known extension - could ask user for the format here.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14227
        "/ currently default to tiff format.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14228
        "/
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14229
        readerClass := self class defaultImageFileWriter.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14230
        'Image [warning]: unknown extension - cannot figure out format - using default (',readerClass name,')' errorPrintCR.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14231
    ].
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14232
    ^ self saveOn:aFileName quality:qualityPercentOrNil using:readerClass
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14233
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14234
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14235
    "
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14236
     |image|
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14237
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14238
     image := Image fromFile:'goodies/bitmaps/RCube.tiff'.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14239
     image saveOn:'myImage.tiff'.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14240
     image saveOn:'myImage.xbm'.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14241
     image saveOn:'myImage.xpm'.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14242
     image saveOn:'myImage.xwd'.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14243
    "
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14244
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14245
    "Modified: 30.6.1997 / 22:06:34 / cg"
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14246
!
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14247
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14248
saveOn:aFileName quality:qualityPercentOrNil using:readerClass
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14249
    "save the receiver using the representation class
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14250
     (which is usually a concrete subclasses of ImageReader).
3913
25e103c84773 comments
Claus Gittinger <cg@exept.de>
parents: 3912
diff changeset
 14251
     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
 14252
7173
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14253
    ^ readerClass save:self onFile:aFileName quality:qualityPercentOrNil
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14254
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14255
    "
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 14256
     |anImage|
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 14257
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14258
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 14259
     anImage saveOn:'myImage.tiff' using:TIFFReader.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14260
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14261
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14262
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14263
     |anImage|
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14264
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14265
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 14266
     anImage saveOn:'myImage.xbm' using:XBMReader.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14267
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14268
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14269
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14270
     |anImage|
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14271
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14272
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14273
     Image cannotRepresentImageSignal handle:[:ex |
7173
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14274
        self warn:'cannot save the image in this format'
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14275
     ] do:[
7173
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14276
        anImage saveOn:'myImage.xbm' using:XBMReader.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14277
     ]
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14278
    "
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14279
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14280
    "
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14281
     |anImage|
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14282
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14283
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14284
     anImage saveOn:'myImage.xpm' using:XPMReader.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14285
    "
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14286
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14287
    "
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14288
     |anImage|
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14289
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14290
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14291
     anImage saveOn:'myImage.gif' using:GIFReader.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14292
    "
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14293
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14294
    "Modified: 10.4.1997 / 17:49:26 / cg"
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14295
!
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14296
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14297
saveOn:aFileName using:readerClass
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14298
    "save the receiver using the representation class
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14299
     (which is usually a concrete subclasses of ImageReader).
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14300
     May raise a signal, if the image cannot be written by the reader."
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14301
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14302
    ^ readerClass save:self onFile:aFileName quality:nil
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14303
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14304
    "
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14305
     |anImage|
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14306
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14307
     anImage := Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif'.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14308
     anImage saveOn:'myImage.tiff' using:TIFFReader.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14309
     (Depth24Image fromImage:anImage) saveOn:'myImage.jpg' using:JPEGReader.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14310
     anImage saveOn:'myImage50.tiff' quality:50 using:TIFFReader.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14311
     (Depth24Image fromImage:anImage) saveOn:'myImage50.jpg' quality:50 using:JPEGReader.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14312
    "
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14313
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14314
    "
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14315
     |anImage|
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14316
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14317
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14318
     anImage saveOn:'myImage.xbm' using:XBMReader.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14319
    "
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14320
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14321
    "
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14322
     |anImage|
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14323
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14324
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14325
     Image cannotRepresentImageSignal handle:[:ex |
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14326
        self warn:'cannot save the image in this format'
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14327
     ] do:[
075306bcac68 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
 14328
        anImage saveOn:'myImage.xbm' using:XBMReader.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14329
     ]
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14330
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14331
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14332
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14333
     |anImage|
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14334
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14335
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 14336
     anImage saveOn:'myImage.xpm' using:XPMReader.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14337
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14338
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14339
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14340
     |anImage|
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14341
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14342
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 14343
     anImage saveOn:'myImage.gif' using:GIFReader.
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 14344
    "
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 14345
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14346
    "Modified: 10.4.1997 / 17:49:26 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 14347
! !
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14348
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14349
!Image methodsFor:'screen capture'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14350
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14351
from:aDrawable in:aRectangle
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14352
    "read an image from aDrawable.
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14353
     This may be a device Form, a view or the rootView.
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14354
     If its a view or rootView, it must be completely visible (or have
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14355
     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
 14356
     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
 14357
     and to read hardcopy images from the screen."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14358
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14359
    | visType
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14360
     x        "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14361
     y        "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14362
     w        "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14363
     h        "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14364
     dstIndex "{ Class: SmallInteger }"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14365
     srcIndex "{ Class: SmallInteger }"
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14366
     srcRow   "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14367
     dstRow   "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14368
     inData tmpData usedPixels mapSize
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14369
     map bytesPerLine
2534
35d91dcc4604 removed unused local
Claus Gittinger <cg@exept.de>
parents: 2533
diff changeset
 14370
     bitOrder spaceBitsPerPixel
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14371
     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
 14372
     bitsR "{ Class: SmallInteger }"
e2c3f84ff31f fixed pixmap readout for win32, where red and green are exchanged
Claus Gittinger <cg@exept.de>
parents: 3518
diff changeset
 14373
     bitsG "{ Class: SmallInteger }"
e2c3f84ff31f fixed pixmap readout for win32, where red and green are exchanged
Claus Gittinger <cg@exept.de>
parents: 3518
diff changeset
 14374
     bitsB "{ Class: SmallInteger }"
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14375
     maskR "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14376
     maskG "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14377
     maskB "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14378
     shR "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14379
     shG "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14380
     shB "{ Class: SmallInteger }"
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
 14381
     shR2 "{ Class: SmallInteger }"
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
 14382
     shG2 "{ Class: SmallInteger }"
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
 14383
     shB2 "{ Class: SmallInteger }"
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14384
     r "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14385
     g "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14386
     b "{ Class: SmallInteger }"
2019
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 14387
     word "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14388
     lword
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14389
     device ddepth isMSB bpp|
2019
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 14390
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 14391
    depth := self depth.
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14392
    bpp := "bitsPerPixel :=" self bitsPerPixel.
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14393
927
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 924
diff changeset
 14394
    device := aDrawable graphicsDevice.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14395
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14396
    (aDrawable isForm and:[aDrawable depth == 1]) ifTrue:[
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14397
        "/ a monochrome bitmap ?
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14398
        visType := #StaticGray.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14399
        ddepth := 1.
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14400
    ] ifFalse:[
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14401
        (aDrawable isForm) ifFalse:[
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14402
            "
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14403
             get some attributes of the display device
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14404
            "
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14405
            visType := device visualType.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14406
            ddepth := device depth.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14407
        ] ifTrue:[
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14408
            ddepth := aDrawable depth.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14409
            visType := aDrawable photometric
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14410
        ].
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14411
    ].
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14412
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14413
    "/ kludge for 15bit XFree server
2019
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 14414
    ddepth == 15 ifTrue:[
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14415
        ddepth := 16
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14416
    ].
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14417
4421
bcc5886c989c form -> image conversion fixes
james
parents: 4420
diff changeset
 14418
    aDrawable isForm ifTrue:[
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14419
        photometric := aDrawable photometric.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14420
        samplesPerPixel := ddepth == 24 ifTrue:3 ifFalse:1.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14421
        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
 14422
    ] ifFalse:[
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14423
        (visType == #StaticGray) ifTrue:[
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14424
            (device blackpixel == 0) ifTrue:[
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14425
                photometric := #blackIs0
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14426
            ] ifFalse:[
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14427
                photometric := #whiteIs0
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14428
            ].
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14429
            samplesPerPixel := 1.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14430
            bpp := "bitsPerPixel :=" ddepth.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14431
            bitsPerSample := ByteArray with:bpp.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14432
        ] ifFalse:[
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14433
            ((visType == #PseudoColor) or:[(visType == #StaticColor) or:[visType == #GrayScale]]) ifTrue:[
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14434
                photometric := #palette.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14435
                samplesPerPixel := 1.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14436
                bpp := "bitsPerPixel :=" ddepth.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14437
                bitsPerSample := ByteArray with:bpp.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14438
            ] ifFalse:[
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14439
                ((visType == #TrueColor) or:[visType == #DirectColor]) ifTrue:[
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14440
                    photometric := #rgb.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14441
                    samplesPerPixel := 3.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14442
    "/                bpp := "bitsPerPixel :=" depth.
4421
bcc5886c989c form -> image conversion fixes
james
parents: 4420
diff changeset
 14443
    "/                bitsPerSample := ByteArray with:device bitsRed
bcc5886c989c form -> image conversion fixes
james
parents: 4420
diff changeset
 14444
    "/                                       with:device bitsGreen
bcc5886c989c form -> image conversion fixes
james
parents: 4420
diff changeset
 14445
    "/                                       with:device bitsBlue
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14446
                    bpp := "bitsPerPixel :=" 24.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14447
                    bitsPerSample := #(8 8 8).
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14448
                ] ifFalse:[
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14449
                    self error:'screen visual not supported'.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14450
                    ^ nil
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14451
                ]
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14452
            ]
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14453
        ].
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14454
    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14455
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14456
    "
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14457
     dont know yet, how the display pads; assume worst case,
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14458
     offering enough space for 32 bit padding
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14459
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14460
    w := width := aRectangle width.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14461
    h := height := aRectangle height.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14462
    x := aRectangle left.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14463
    y := aRectangle top.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14464
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14465
    "
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14466
     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
 14467
     (its too late when info is present ...)
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14468
    "
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14469
    spaceBitsPerPixel := bpp.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14470
    (bpp > 8) ifTrue:[
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14471
        spaceBitsPerPixel := 16.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14472
        (bpp > 16) ifTrue:[
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14473
            spaceBitsPerPixel := 32.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14474
            (bpp > 32) ifTrue:[
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14475
                spaceBitsPerPixel := bpp.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14476
            ]
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14477
        ]
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14478
    ].
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14479
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14480
    bytesPerLine := (w * spaceBitsPerPixel + 31) // 32 * 4.
3561
e2c3f84ff31f fixed pixmap readout for win32, where red and green are exchanged
Claus Gittinger <cg@exept.de>
parents: 3518
diff changeset
 14481
    "/ inData := ByteArray uninitializedNew:(bytesPerLine * height).
e2c3f84ff31f fixed pixmap readout for win32, where red and green are exchanged
Claus Gittinger <cg@exept.de>
parents: 3518
diff changeset
 14482
    inData := ByteArray new:(bytesPerLine * height).
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14483
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14484
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14485
     get the pixels
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14486
    "
1459
84e80b355553 splitted getBitsFrom into getBitsFromPixmap
Claus Gittinger <cg@exept.de>
parents: 1446
diff changeset
 14487
    aDrawable isForm ifTrue:[
7206
Claus Gittinger <cg@exept.de>
parents: 7191
diff changeset
 14488
        (aDrawable id isNil and:[aDrawable bits notNil]) ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 7191
diff changeset
 14489
            info := Dictionary new
Claus Gittinger <cg@exept.de>
parents: 7191
diff changeset
 14490
                        at:#bitsPerPixel put:(aDrawable depth);
Claus Gittinger <cg@exept.de>
parents: 7191
diff changeset
 14491
                        at:#byteOrder put:#msbFirst;
Claus Gittinger <cg@exept.de>
parents: 7191
diff changeset
 14492
                        at:#bitOrder put:#msbFirst; 
Claus Gittinger <cg@exept.de>
parents: 7191
diff changeset
 14493
                        at:#bytesPerLine put:(aDrawable width * aDrawable depth + 7)//8;
Claus Gittinger <cg@exept.de>
parents: 7191
diff changeset
 14494
                        yourself.
Claus Gittinger <cg@exept.de>
parents: 7191
diff changeset
 14495
            inData := aDrawable bits.
Claus Gittinger <cg@exept.de>
parents: 7191
diff changeset
 14496
        ] ifFalse:[
Claus Gittinger <cg@exept.de>
parents: 7191
diff changeset
 14497
            info := device getBitsFromPixmapId:aDrawable id x:x y:y width:w height:h into:inData.
Claus Gittinger <cg@exept.de>
parents: 7191
diff changeset
 14498
        ]
1459
84e80b355553 splitted getBitsFrom into getBitsFromPixmap
Claus Gittinger <cg@exept.de>
parents: 1446
diff changeset
 14499
    ] ifFalse:[
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14500
        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
 14501
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14502
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14503
    bitsPerPixelIn := info at:#bitsPerPixel.
2533
3af95252b1b3 oops - ISMSB was not assigned
Claus Gittinger <cg@exept.de>
parents: 2532
diff changeset
 14504
3af95252b1b3 oops - ISMSB was not assigned
Claus Gittinger <cg@exept.de>
parents: 2532
diff changeset
 14505
    isMSB := ((info at:#byteOrder) == #msbFirst).
3af95252b1b3 oops - ISMSB was not assigned
Claus Gittinger <cg@exept.de>
parents: 2532
diff changeset
 14506
2029
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 14507
    "/
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 14508
    "/ check if bitorder is what I like (msbFirst)
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 14509
    "/
7206
Claus Gittinger <cg@exept.de>
parents: 7191
diff changeset
 14510
    "/ mhmh - that's not needed
2029
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 14511
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 14512
    bitsPerPixelIn < 8 ifTrue:[
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14513
        bitOrder := info at:#bitOrder.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14514
        bitOrder ~~ #msbFirst ifTrue:[
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14515
            inData
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14516
                expandPixels:8
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14517
                width:(inData size)
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14518
                height:1
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14519
                into:inData
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14520
                mapping:(ImageReader reverseBits "TODO: reverseBitsForDepth:bitsPerPixelIn").
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14521
        ].
2029
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 14522
    ].
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 14523
396
d088e672be8a handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents: 394
diff changeset
 14524
    "
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14525
     check, if the devices padding is different ..
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14526
     or if the bitsPerPixels are different
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14527
    "
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14528
    bytesPerLineIn := (info at:#bytesPerLine).           "what I got"
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14529
    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
 14530
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 14531
    maskR := info at:#redMask ifAbsent:0.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 14532
    maskG := info at:#greenMask ifAbsent:0.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 14533
    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
 14534
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14535
    ((bytesPerLine ~~ bytesPerLineIn)
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14536
    or:[bitsPerPixelIn ~~ bpp]) ifTrue:[
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14537
        tmpData := inData.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14538
        inData := ByteArray uninitializedNew:(bytesPerLine * height).
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14539
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14540
        srcRow := 1.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14541
        dstRow := 1.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14542
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14543
        bitsPerPixelIn ~~ bpp ifTrue:[
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14544
            "/ for now, only 32 -> 24 is supported
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14545
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14546
            maskR == 0 ifTrue:[
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14547
                bitsR := device bitsRed.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14548
                bitsG := device bitsGreen.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14549
                bitsB := device bitsBlue.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14550
                maskR := (1 bitShift:bitsR) - 1.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14551
                maskG := (1 bitShift:bitsG) - 1.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14552
                maskB := (1 bitShift:bitsB) - 1.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14553
                shR := device shiftRed negated.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14554
                shG := device shiftGreen negated.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14555
                shB := device shiftBlue negated.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14556
            ] ifFalse:[
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14557
                shR := (maskR lowBit - 1) negated.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14558
                bitsR := maskR highBit - maskR lowBit + 1.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14559
                maskR := maskR bitShift:shR.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14560
                shG := (maskG lowBit - 1) negated.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14561
                bitsG := maskG highBit - maskG lowBit + 1.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14562
                maskG := maskG bitShift:shG.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14563
                shB := (maskB lowBit - 1) negated.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14564
                bitsB := maskB highBit - maskB lowBit + 1.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14565
                maskB := maskB bitShift:shB.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14566
            ].
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14567
            shR2 := (8 - bitsR).
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14568
            shG2 := (8 - bitsG).
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14569
            shB2 := (8 - bitsB).
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14570
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14571
            ((bitsPerPixelIn == 32) and:[bpp == 24]) ifTrue:[
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14572
                "/ 'reformatting 32->24...' printNL.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14573
                1 to:h do:[:hi |
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14574
                    srcIndex := srcRow.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14575
                    dstIndex := dstRow.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14576
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14577
                    1 to:w do:[:wi |
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14578
                        lword := tmpData doubleWordAt:srcIndex MSB:isMSB.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14579
                        r := (lword bitShift:shR) bitAnd:maskR.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14580
                        g := (lword bitShift:shG) bitAnd:maskG.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14581
                        b := (lword bitShift:shB) bitAnd:maskB.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14582
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14583
                        inData at:dstIndex   put:r.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14584
                        inData at:dstIndex+1 put:g.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14585
                        inData at:dstIndex+2 put:b.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14586
                        srcIndex := srcIndex + 4.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14587
                        dstIndex := dstIndex + 3.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14588
                    ].
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14589
                    dstRow := dstRow + bytesPerLine.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14590
                    srcRow := srcRow + bytesPerLineIn
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14591
                ]
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14592
            ] ifFalse:[
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14593
                ((bitsPerPixelIn == 16) and:[bpp == 24]) ifTrue:[
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14594
                    "/ 'reformatting 16->24...' printNL.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14595
                    1 to:h do:[:hi |
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14596
                        srcIndex := srcRow.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14597
                        dstIndex := dstRow.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14598
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14599
                        1 to:w do:[:wi |
7210
f3e957711d10 call the renamed basic methods for short access:
Claus Gittinger <cg@exept.de>
parents: 7206
diff changeset
 14600
                            word := tmpData unsignedInt16At:srcIndex MSB:isMSB.
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14601
                            r := (word bitShift:shR) bitAnd:maskR.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14602
                            g := (word bitShift:shG) bitAnd:maskG.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14603
                            b := (word bitShift:shB) bitAnd:maskB.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14604
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14605
                            inData at:dstIndex   put:(r bitShift:shR2).
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14606
                            inData at:dstIndex+1 put:(g bitShift:shG2).
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14607
                            inData at:dstIndex+2 put:(b bitShift:shB2).
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14608
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14609
                            srcIndex := srcIndex + 2.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14610
                            dstIndex := dstIndex + 3.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14611
                        ].
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14612
                        dstRow := dstRow + bytesPerLine.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14613
                        srcRow := srcRow + bytesPerLineIn
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14614
                    ]
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14615
                ] ifFalse:[
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14616
                    ('Image [warning]: unsupported depth combination: ' , bitsPerPixelIn printString , ' -> ' ,
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14617
                                                        bpp printString) errorPrintCR.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14618
                    self shouldImplement.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14619
                    ^ nil
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14620
                ]
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14621
            ].
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14622
        ] ifFalse:[
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14623
            "/
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14624
            "/ repad in the buffer
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14625
            "/
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14626
            1 to:h do:[:hi |
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14627
                inData replaceFrom:dstRow to:(dstRow + bytesPerLine - 1)
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14628
                              with:tmpData startingAt:srcRow.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14629
                dstRow := dstRow + bytesPerLine.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14630
                srcRow := srcRow + bytesPerLineIn
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14631
            ]
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14632
        ]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14633
    ] ifFalse:[
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14634
        (bytesPerLine * height) ~~ inData size ifTrue:[
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14635
            tmpData := inData.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14636
            inData := ByteArray uninitializedNew:(bytesPerLine * height).
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14637
            inData replaceFrom:1 to:bytesPerLine * height with:tmpData startingAt:1
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14638
        ]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14639
    ].
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 14640
    self bits:inData.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14641
3864
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
 14642
    "/
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
 14643
    "/  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
 14644
    "/
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
 14645
    photometric == #palette ifTrue:[
7180
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14646
        "/
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14647
        "/ what we have now are the color numbers - still need the r/g/b values.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14648
        "/ find out, which colors are in the picture
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14649
        "/
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14650
        usedPixels := inData usedValues.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14651
        mapSize := usedPixels max + 1.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14652
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14653
        "get the palette"
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14654
        map := Array new:mapSize.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14655
        usedPixels do:[:colorIndex |
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14656
            |i|
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14657
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14658
            i := colorIndex + 1.
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14659
            device getRGBFrom:colorIndex into:[:r :g :b |
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14660
                map at:i put:(Color red:r green:g blue:b)
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14661
            ]
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14662
        ].
40dcb4638d93 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 7176
diff changeset
 14663
        self setColorMap:map.
1644
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 14664
    ].
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 14665
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
 14666
    "Modified: / 9.1.1998 / 21:32:36 / stefan"
2054
3d1619286006 fixed readout from 32bit servers
Claus Gittinger <cg@exept.de>
parents: 2050
diff changeset
 14667
    "Modified: / 7.2.1998 / 18:23:07 / cg"
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14668
!
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14669
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14670
fromScreen:aRectangle
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 14671
    "read an image from the display screen.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 14672
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14673
	      it may not work from within a buttonMotion
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14674
	      (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
 14675
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14676
    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14677
	fromScreen:aRectangle
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14678
	on:Screen current
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14679
	grab:true
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14680
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 14681
    "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
 14682
!
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14683
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14684
fromScreen:aRectangle on:aDevice
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14685
    "read an image from aDevices display screen.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14686
     Since I have no other displays, only the MonoChrome, StaticGrey
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14687
     and PseudoColor cases have been tested ...
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14688
     (especially True- and DirectColor may be wrong).
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 14689
     Late note: 24bit rgb now also works.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 14690
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14691
	      it may not work from within a buttonMotion
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14692
	      (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
 14693
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14694
    ^ self
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14695
	fromScreen:aRectangle
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14696
	on:aDevice
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14697
	grab:true
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 14698
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 14699
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 14700
     Image fromScreen:((0 @ 0) corner:(100 @ 100)) on:Display
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 14701
     Image fromScreen:((0 @ 0) corner:(500 @ 500)) on:Display
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 14702
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 14703
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 14704
    "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
 14705
!
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14706
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14707
fromScreen:aRectangle on:aDevice grab:doGrab
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14708
    "read an image from aDevices display screen.
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14709
     If the doGrab argument is true, the display
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14710
     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
 14711
     shown while the readout is done.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14712
     Since I have no other displays, only the MonoChrome, StaticGrey
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14713
     and PseudoColor cases have been tested ...
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14714
     (especially True- and DirectColor may be wrong).
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 14715
     Late note: 24bit rgb now also works.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 14716
     WARNING: with doGrab true, this temporarily grabs the display
6613
3b0f0fb40c2c class: Image
Claus Gittinger <cg@exept.de>
parents: 6592
diff changeset
 14717
              and it may not work from within a buttonMotion
3b0f0fb40c2c class: Image
Claus Gittinger <cg@exept.de>
parents: 6592
diff changeset
 14718
              (use with a false grabArg then)."
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 14719
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 14720
    |curs rootView prevGrab|
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 14721
6613
3b0f0fb40c2c class: Image
Claus Gittinger <cg@exept.de>
parents: 6592
diff changeset
 14722
    curs := nil.
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 14723
"/    doGrab ifTrue:[ |cid|
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14724
"/        curs := Cursor sourceForm:(Image fromFile:'bitmaps/Camera.xbm')
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14725
"/                         maskForm:(Image fromFile:'bitmaps/Camera_m.xbm')
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14726
"/                          hotSpot:16@16.
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14727
"/        curs notNil ifTrue:[
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14728
"/            cid := (curs onDevice:aDevice) id
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14729
"/        ].
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14730
"/    ].
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14731
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14732
    "
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14733
     actually have to grabServer ... but thats not yet available
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14734
    "
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14735
    rootView := aDevice rootView.
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14736
    doGrab ifTrue:[
6613
3b0f0fb40c2c class: Image
Claus Gittinger <cg@exept.de>
parents: 6592
diff changeset
 14737
        prevGrab := aDevice activePointerGrab.
3b0f0fb40c2c class: Image
Claus Gittinger <cg@exept.de>
parents: 6592
diff changeset
 14738
        aDevice grabPointerInView:rootView withCursor:curs.
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14739
    ].
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14740
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14741
    "
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14742
     get the pixels
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14743
    "
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14744
    [
6613
3b0f0fb40c2c class: Image
Claus Gittinger <cg@exept.de>
parents: 6592
diff changeset
 14745
        self from:rootView in:aRectangle.
3605
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
 14746
    ] ensure:[
6613
3b0f0fb40c2c class: Image
Claus Gittinger <cg@exept.de>
parents: 6592
diff changeset
 14747
        doGrab ifTrue:[
3b0f0fb40c2c class: Image
Claus Gittinger <cg@exept.de>
parents: 6592
diff changeset
 14748
            aDevice ungrabPointer.
3b0f0fb40c2c class: Image
Claus Gittinger <cg@exept.de>
parents: 6592
diff changeset
 14749
            prevGrab notNil ifTrue:[
3b0f0fb40c2c class: Image
Claus Gittinger <cg@exept.de>
parents: 6592
diff changeset
 14750
                 aDevice grabPointerInView:prevGrab.
3b0f0fb40c2c class: Image
Claus Gittinger <cg@exept.de>
parents: 6592
diff changeset
 14751
            ]
3b0f0fb40c2c class: Image
Claus Gittinger <cg@exept.de>
parents: 6592
diff changeset
 14752
        ]
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14753
    ]
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14754
3092
0f1a9ec64574 restore grab after #imageFromUser
ca
parents: 3059
diff changeset
 14755
    "
0f1a9ec64574 restore grab after #imageFromUser
ca
parents: 3059
diff changeset
 14756
     Image fromScreen:((100@100) corner:(200@200)) on:Display grab:false
0f1a9ec64574 restore grab after #imageFromUser
ca
parents: 3059
diff changeset
 14757
     Image fromScreen:((100@100) corner:(200@200)) on:Display grab:true
0f1a9ec64574 restore grab after #imageFromUser
ca
parents: 3059
diff changeset
 14758
    "
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14759
!
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14760
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14761
photometricFromScreen:aDevice
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14762
    "read aDevices display photometric and set my colormap for it.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14763
     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
 14764
     or from an offScreen bitmap, for correct pixel interpretation."
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14765
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14766
    |depth visType bitsPerPixel|
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14767
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14768
    "
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14769
     get some attributes of the display device
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14770
    "
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14771
    visType := aDevice visualType.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14772
    depth := aDevice depth.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14773
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14774
    "/ kludge for 15bit XFree server
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14775
    depth == 15 ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14776
	depth := 16
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14777
    ].
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14778
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14779
    (visType == #StaticGray) ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14780
	(aDevice blackpixel == 0) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14781
	    photometric := #blackIs0
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14782
	] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14783
	    photometric := #whiteIs0
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14784
	].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14785
	samplesPerPixel := 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14786
	bitsPerPixel := depth.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14787
	bitsPerSample := ByteArray with:bitsPerPixel.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14788
	"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14789
	 were done, the pixel values are the grey values
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14790
	"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14791
	^ self
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14792
    ].
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14793
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14794
    ((visType == #TrueColor) or:[visType == #DirectColor]) ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14795
	photometric := #rgb.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14796
	samplesPerPixel := 3.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14797
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14798
	"/ for now - only support 24bit TrueColor
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14799
	depth ~~ 24 ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14800
	    'IMAGE: unsupported display depth' errorPrintCR.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14801
	].
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14802
"/                bitsPerPixel := depth.
4115
0e783379a6b0 Use ByteArray for bitsPerSample (255 should be enough ;-)
Stefan Vogel <sv@exept.de>
parents: 4109
diff changeset
 14803
"/                bitsPerSample := ByteArray with:aDevice bitsRed
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14804
"/                                       with:aDevice bitsGreen
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14805
"/                                       with:aDevice bitsBlue
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14806
	bitsPerPixel := 24.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14807
	bitsPerSample := #[8 8 8].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14808
	"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14809
	 were done, the pixel values are the rgb values
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14810
	"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14811
	^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14812
    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14813
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14814
    ((visType ~~ #PseudoColor)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14815
    and:[(visType ~~ #StaticColor)
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14816
    and:[visType ~~ #GrayScale]]) ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14817
	self error:'screen visual not supported'.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14818
	^ nil
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14819
    ].
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14820
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14821
    photometric := #palette.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14822
    samplesPerPixel := 1.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14823
    bitsPerPixel := depth.
4115
0e783379a6b0 Use ByteArray for bitsPerSample (255 should be enough ;-)
Stefan Vogel <sv@exept.de>
parents: 4109
diff changeset
 14824
    bitsPerSample := ByteArray with:bitsPerPixel.
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14825
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14826
    "
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14827
     still need the pixels r/g/b values ...
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14828
    "
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
 14829
    self setColorMap:aDevice colorMap
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14830
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14831
    "Modified: 11.7.1996 / 11:11:34 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14832
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14833
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14834
!Image methodsFor:'virtual anti-aliased'!
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14835
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
 14836
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
 14837
    |isBottom isLeft additionalY workPoint startX endX pixels pixelPos percent distance nearestKey tmp|
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14838
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14839
    isBottom := bottomOrTop sameAs:'bottom'.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14840
    isBottom ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14841
	additionalY := -1.
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14842
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14843
	additionalY := 1.
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14844
    ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14845
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14846
    isLeft := leftOrRight sameAs:'left'.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14847
    isLeft ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14848
	workPoint := (xRun - 1)@yRun.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14849
	[(
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14850
	    (tempForm atX:workPoint x y:workPoint y) == 0 and:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14851
	    (tempForm atX:workPoint x y:workPoint y + additionalY) == 1]) and:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14852
	    (tempForm atX:workPoint x - 1 y:workPoint y + additionalY) == 1]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14853
	] whileTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14854
	    startX := workPoint x.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14855
	    endX isNil ifTrue:[endX := workPoint x].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14856
	    workPoint := (workPoint x - 1)@yRun.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14857
	].
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14858
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14859
	workPoint := (xRun + 1)@yRun.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14860
	[(
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14861
	    (tempForm atX:workPoint x y:workPoint y) == 0 and:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14862
	    (tempForm atX:workPoint x y:workPoint y + additionalY) == 1]) and:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14863
	    (tempForm atX:workPoint x + 1 y:workPoint y + additionalY) == 1]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14864
	] whileTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14865
	    endX := workPoint x.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14866
	    startX isNil ifTrue:[startX := workPoint x].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14867
	    workPoint := (workPoint x + 1)@yRun.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14868
	].
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14869
    ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14870
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14871
    (startX notNil and:[endX notNil]) ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14872
	startX = endX ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14873
	    self atImageAndMask:startX@yRun putValue:((colorDictionary at:aColor) at:blendStart).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14874
	] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14875
	    pixels := (endX - startX) + 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14876
	    startX to:endX do:[:x |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14877
		isLeft ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14878
		    pixelPos := (x - startX) + 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14879
		] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14880
		    pixelPos := (endX - x) + 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14881
		].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14882
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14883
		percent := (100 / (pixels / pixelPos)) asFloat / 100.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14884
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14885
		(colorDictionary at:aColor) keys do:[:aKey |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14886
		    nearestKey isNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14887
			distance := percent dist:aKey.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14888
			nearestKey := aKey.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14889
		    ] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14890
			tmp := percent dist:aKey.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14891
			distance > tmp ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14892
			    distance := tmp.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14893
			    nearestKey := aKey.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14894
			].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14895
		    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14896
		].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14897
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14898
		self atImageAndMask:x@yRun putValue:((colorDictionary at:aColor) at:nearestKey).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14899
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14900
		distance := nil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14901
		nearestKey := nil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14902
	    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14903
	].
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14904
    ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14905
!
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14906
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
 14907
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
 14908
    |isLeft isBottom additionalX workPoint startY endY pixels pixelPos percent distance nearestKey tmp|
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14909
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14910
    isLeft := leftOrRight sameAs:'left'.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14911
    isLeft ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14912
	additionalX := 1.
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14913
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14914
	additionalX := -1.
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14915
    ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14916
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14917
    isBottom := bottomOrTop sameAs:'bottom'.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14918
    isBottom ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14919
	workPoint := xRun@(yRun + 1).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14920
	[(
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14921
	    (tempForm atX:workPoint x y:workPoint y) == 0 and:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14922
	    (tempForm atX:workPoint x + additionalX y:workPoint y) == 1]) and:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14923
	    (tempForm atX:workPoint x + additionalX y:workPoint y + 1) == 1]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14924
	] whileTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14925
	    endY := workPoint y.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14926
	    startY isNil ifTrue:[startY := workPoint y].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14927
	    workPoint := xRun@(workPoint y + 1).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14928
	].
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14929
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14930
	workPoint := xRun@(yRun - 1).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14931
	[(
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14932
	    (tempForm atX:workPoint x y:workPoint y) == 0 and:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14933
	    (tempForm atX:workPoint x + additionalX y:workPoint y) == 1]) and:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14934
	    (tempForm atX:workPoint x + additionalX y:workPoint y - 1) == 1]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14935
	] whileTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14936
	    startY := workPoint y.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14937
	    endY isNil ifTrue:[endY := workPoint y].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14938
	    workPoint := xRun@(workPoint y - 1).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14939
	].
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14940
    ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14941
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14942
    (startY notNil and:[endY notNil]) ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14943
	startY = endY ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14944
	    self atImageAndMask:xRun@startY putValue:((colorDictionary at:aColor) at:blendStart).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14945
	] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14946
	    pixels := (endY - startY) + 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14947
	    startY to:endY do:[:y |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14948
		isBottom ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14949
		    pixelPos := (endY - y) + 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14950
		] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14951
		    pixelPos := (y - startY) + 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14952
		].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14953
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14954
		percent := (100 / (pixels / pixelPos)) asFloat / 100.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14955
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14956
		(colorDictionary at:aColor) keys do:[:aKey |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14957
		    nearestKey isNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14958
			distance := percent dist:aKey.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14959
			nearestKey := aKey.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14960
		    ] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14961
			tmp := percent dist:aKey.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14962
			distance > tmp ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14963
			    distance := tmp.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14964
			    nearestKey := aKey.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14965
			].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14966
		    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14967
		].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14968
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14969
		self atImageAndMask:xRun@y putValue:((colorDictionary at:aColor) at:nearestKey).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14970
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14971
		distance := nil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14972
		nearestKey := nil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14973
	    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14974
	].
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14975
    ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14976
! !
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14977
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
 14978
!Image class methodsFor:'documentation'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14979
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14980
version
6894
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
 14981
    ^ '$Header$'
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
 14982
!
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
 14983
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
 14984
version_CVS
6894
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
 14985
    ^ '$Header$'
6912
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
 14986
!
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
 14987
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
 14988
version_HG
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
 14989
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
 14990
    ^ '$Changeset: <not expanded> $'
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
 14991
! !
3759
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
 14992
6037
eea2343b0b1e Refactoring:
Stefan Vogel <sv@exept.de>
parents: 5956
diff changeset
 14993
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14994
Image initialize!